[Python-Dev] PEP 447: add type.locallookup (original) (raw)

Steven D'Aprano steve at pearwood.info
Fri Sep 13 05:59:17 CEST 2013


On Fri, Sep 13, 2013 at 03:04:49AM +0000, Steve Dower wrote:

What about getlocalattribute or getattributenorecurse? Long, but this isn't going to be used often.

This has nothing to do with locals, nor does it have anything to do with recursion, so both those names are misleading.

Putting "type" or "class" in the name would be misleading. It's an instance method (that is most useful when implemented on a metaclass).

Regardless of whether it is an instance method or not, by default it performs the lookup on the type. Hence the C function _PyType_Lookup and hence my suggestion typelookup.

But I think that typelookup does describe quite well what the method does. It looks up on the type. The PEP is fairly clear on how this is supposed to work, e.g. the default type. method will look up in the class/type dict. PEP 447 includes an example of how you might implement this in Python:

class MetaType(type): def locallookup(cls, name): try: return cls.dict[name] except KeyError: raise AttributeError(name) from None

"local lookup" doesn't even come close to describing what the method does or why you would use it. It suggests something to do with locals, which is not the case. Neither does getattributenorecurse, which suggests looking up an attribute on an object without following the inheritance hierarchy, e.g. looking in the instance dict but not the class dict. So the complete opposite of what it actually does.

-- Steven



More information about the Python-Dev mailing list