My question:  Does that __getattr__ method have 'self' as the first parameter?  If not, why not, and if so, shouldn't
PEP 562's __getattr__ also take a 'self'?

--
~Ethan~
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/brett%40python.org
">

(original) (raw)



On Wed, 15 Nov 2017 at 16:27 Ethan Furman <ethan@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\_\_ ?

There's actually an example in the stdlib thanks to importlib.util.LazyLoader, although it uses \_\_getattribute\_\_() and not \_\_getattr\_\_():
https://github.com/python/cpython/blob/d505a29a15a6f9315d8c46445b8a0cccfc2048b8/Lib/importlib/util.py#L212
-Brett


My question: Does that \_\_getattr\_\_ method have 'self' as the first parameter? If not, why not, and if so, shouldn't
PEP 562's \_\_getattr\_\_ also take a 'self'?

\--
\~Ethan\~
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/brett%40python.org