On 19/11/17 20:41, Serhiy Storchaka wrote:
19.11.17 22:24, Mark Shannon пише:
Just one comment. Could the new behaviour of attribute lookup on a module be spelled out more explicitly please?


I'm guessing it is now something like:

`module.__getattribute__` is now equivalent to:

def __getattribute__(mod, name):
     try:
         return object.__getattribute__(mod, name)
     except AttributeError:
         try:
             getter = mod.__dict__["__getattr__"]
         except KeyError:
             raise AttributeError(f"module has no attribute '{name}'")
         return getter(name)

I think it is better to describe in the terms of __getattr__.

def ModuleType.__getattr__(mod, name):
     try:
         getter = mod.__dict__["__getattr__"]
     except KeyError:
         raise AttributeError(f"module has no attribute '{name}'")
     return getter(name)

The implementation of ModuleType.__getattribute__ will be not changed (it is inherited from the object type).

Not quite, ModuleType overrides object.__getattribute__ in order to provide a better error message. So with your suggestion, the change would be to *not* override object.__getattribute__ and provide the above ModuleType.__getattr__

Cheers,
Mark.
_______________________________________________
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/archive%40mail-archive.com

Reply via email to