This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.snow
Recipients Guido.van.Rossum, Mark.Shannon, benjamin.peterson, brett.cannon, eltoder, eric.snow, gvanrossum, larry, lemburg, ncoghlan, njs, pitrou, python-dev, rhettinger, serhiy.storchaka, vstinner
Date 2015-09-06.02:57:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1441508267.33.0.904388613358.issue24912@psf.upfronthosting.co.za>
In-reply-to
Content
While I recognize the practicality/purity argument here, I somewhat agree with Mark.  Assigning to module.__class__ makes sense for the use case, but it does open up a number of negative possible side effects (e.g. changing sys.__class__).  Ideally it would be restricted to just the currently running module, but doing that through __class__ assignment is not a great idea.  Having a dedicated builtin function or even syntax would make more sense.

In some ways I'm reminded of __metaclass__ in Python 2 class definitions.  Something like that has come up before but didn't get a lot of momentum at the time.  Ultimately I'd like to see a more explicit mechanism to meet the need that motivated the __class__ change here (as well as the replace-this-module-in-sys-modules technique). [1] While you can already accomplish this via a custom finder, that's not the most convenient tool for this sort of situation.

FWIW, if assigning to sys.modules[__name__].__class__ is the blessed way then we should make it official in the language reference.  The same goes for modules replacing themselves in sys.modules.  If we have reservations about making either official (which I for one do [2]) then we should work on a more appropriate official solution.


[1] It all boils down to customizing the current module's type from within the module rather than from outside (using a custom loader).
[2] Neither spelling is very friendly.
History
Date User Action Args
2015-09-06 02:57:47eric.snowsetrecipients: + eric.snow, lemburg, gvanrossum, brett.cannon, rhettinger, ncoghlan, pitrou, vstinner, larry, benjamin.peterson, njs, Mark.Shannon, python-dev, eltoder, serhiy.storchaka, Guido.van.Rossum
2015-09-06 02:57:47eric.snowsetmessageid: <1441508267.33.0.904388613358.issue24912@psf.upfronthosting.co.za>
2015-09-06 02:57:47eric.snowlinkissue24912 messages
2015-09-06 02:57:46eric.snowcreate