You can do things like this with exec(): class SafeDict(dict): curated_keys = {"a", "b", "c"} def __setitem__(self, k, v): if k not i self.curated_keys: raise Exception(f"{k!r} key not allowed") super().__setitem__(k, v)
locals_dict = SafeDict() globals_dict = SafeDict() exec("d=1", locals_dict, globals_dict) # Exception: 'd' key not allowed You can do all sorts of things using that technique, including the way assignment to variables is handled. Beyond that, I declare my competence in this matter to have been hereby exceeded, since I really don't follow or understand the HDL paradigm you are working in. Maybe others might be able to help.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/