dunder-docs (was Python is DOOMED! Again!)

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Feb 2 02:15:56 EST 2015


Gregory Ewing wrote:

> Steven D'Aprano wrote:
>>     [quote]
>>     If the object has a method named __dir__(), this method will
>>     be called and must return the list of attributes.
>>     [end quote]
>> 
>> The first inaccuracy is that like all (nearly all?) dunder methods,
>> Python only looks for __dir__ on the class, not the instance itself.
> 
> It says "method", not "attribute", so technically
> it's correct. The methods of an object are defined
> by what's in its class.

Citation please. I'd like to see where that is defined.

Even if it is so defined, the definition is wrong. You can define methods on 
an instance. I showed an example of an instance with its own personal 
__dir__ method, and showed that dir() ignores it if the instance belongs to 
a new-style class but uses it if it is an old-style class.



-- 
Steven




More information about the Python-list mailing list