On 2017-09-12, Nathaniel Smith wrote:
> If you're ok with replacing the object in sys.modules then the ability to
> totally customize your module's type has existed since the dawn era. And if
> you're not ok with that, then it's still existed since 3.5 via the
> mechanism of assigning to __class__ to change the type in-place.

It doesn't quite work though.  Swapping out or assigning to
__class__, and then running:

    exec(code, module.__dict__)

does not have the expected behavior.  LOAD_NAME/LOAD_GLOBAL does not
care about your efforts.  Accessing module globals from outside the
module does work as that is a getattr call.  That is a weird
inconsistency that should be fixed if it is not too painful.

Coming up with handy syntax or whatever is a minor problem.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to