<div dir="auto"><div><div class="gmail_extra"><div class="gmail_quote">On Sep 12, 2017 7:08 AM, "Ionel Cristian Mărieș via Python-ideas" <<a href="mailto:python-ideas@python.org">python-ideas@python.org</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:trebuchet ms,sans-serif">Wouldn't a better approach be a way to customize the type of the module? That would allow people to define behavior for almost anything (__call__, __getattr__, __setattr__, __dir__, various operators etc). This question shouldn't exist "why can't I customize behavior X in a module when I can do it for a class". Why go half-way.<br></div></div></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">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. So this discussion isn't about adding new functionality per se, but about trying to find some way to provide a little bit of sugar that provides most of the value in a less obscure way.</div><div dir="auto"><br></div><div dir="auto">(And unfortunately there's a chicken and egg problem for using custom module types *without* the __class__ assignment hack, because you can't load any code from a package until after you've created the top level module object. So we've kind of taken custom module types as far as they can go already.)</div><div dir="auto"><br></div><div dir="auto">-n</div></div>