[Python-Dev] Comment on PEP 562 (Module getattr and dir) (original) (raw)
Mark Shannon mark at hotpy.org
Sun Nov 19 15:48:58 EST 2017
- Previous message (by thread): [Python-Dev] Comment on PEP 562 (Module __getattr__ and __dir__)
- Next message (by thread): [Python-Dev] Comment on PEP 562 (Module __getattr__ and __dir__)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Previous message (by thread): [Python-Dev] Comment on PEP 562 (Module __getattr__ and __dir__)
- Next message (by thread): [Python-Dev] Comment on PEP 562 (Module __getattr__ and __dir__)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]