Clarification based on python-dev discussion (#480)

This commit is contained in:
Ivan Levkivskyi 2017-11-21 01:25:18 +01:00 committed by Guido van Rossum
parent 303e46d494
commit 9228c0c923
1 changed files with 7 additions and 4 deletions

View File

@ -113,10 +113,13 @@ an ``AttributeError``::
def __getattr__(name: str) -> Any: ...
This function will be called only if ``name`` is not found in the module
through the normal attribute lookup. Looking up a name as a module global
will bypass module ``__getattr__``. This is intentional, otherwise calling
``__getattr__`` for builtins will significantly harm performance.
If an attribute is not found on a module object through the normal lookup
(i.e. ``object.__getattribute__``), then ``__getattr__`` is searched in
the module ``__dict__`` before raising an ``AttributeError``. If found, it is
called with the attribute name and the result is returned. Looking up a name
as a module global will bypass module ``__getattr__``. This is intentional,
otherwise calling ``__getattr__`` for builtins will significantly harm
performance.
The ``__dir__`` function should accept no arguments, and return
a list of strings that represents the names accessible on module::