getattr and __mro__ (was Re: [Python-Dev] PEP 246, redux)

Alex Martelli aleax at aleax.it
Wed Jan 12 16:52:53 CET 2005


On 2005 Jan 12, at 16:44, Thomas Heller wrote:
    ...
>>    conform = getattr(type(obj), '__conform__', None)
    ...
> I'm confused.  Do you mean that
>
>    getattr(obj, "somemethod")(...)
>
> does something different than
>
>    obj.somemethod(...)
>
> with new style class instances?  Doesn't getattr search the __dict__'s
> along the __mro__ list?

Yes, but getattr(obj, ... ALSO searches obj itself, which is what we're 
trying to avoid here.

getattr(type(obj), ... OTOH has a DIFFERENT problem -- it ALSO searches 
type(type(obj)), the metaclass, which we DON'T want.


Alex



More information about the Python-Dev mailing list