[Python-Dev] module customization

Guido van Rossum guido at python.org
Wed Nov 15 20:49:07 EST 2017


On Wed, Nov 15, 2017 at 4:27 PM, Ethan Furman <ethan at stoneleaf.us> wrote:

> So there are currently two ways to customize a module, with PEP 562
> proposing a third.
>
> The first method involves creating a standard class object, instantiating
> it, and replacing the sys.modules entry with it.
>
> The second way is fairly similar, but instead of replacing the entire
> sys.modules entry, its class is updated to be the class just created --
> something like sys.modules['mymod'].__class__ = MyNewClass .
>
> My request:  Can someone write a better example of the second method?  And
> include __getattr__ ?
>
> My question:  Does that __getattr__ method have 'self' as the first
> parameter?


It does.


> If not, why not, and if so, shouldn't PEP 562's __getattr__ also take a
> 'self'?
>

Not really, since there's only one module (the one containing the
__getattr__ function). Plus we already have a 1-argument module-level
__getattr__ in mypy. See PEP 484.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171115/80b94f71/attachment.html>


More information about the Python-Dev mailing list