[Python-Dev] module customization (original) (raw)

Nathaniel Smith njs at pobox.com
Thu Nov 16 01:12:30 EST 2017


On Wed, Nov 15, 2017 at 5:49 PM, Guido van Rossum <guido at python.org> wrote:

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.

I guess the benefit of taking 'self' would be that it would make it possible (though still a bit odd-looking) to have reusable getattr implementations, like:

mymodule.py

from auto_importer import getattr, dir

auto_import_modules = {"foo", "bar"}

auto_importer.py

def getattr(self, name): if name in self.auto_import_modules: ...

-n

-- Nathaniel J. Smith -- https://vorpus.org



More information about the Python-Dev mailing list