[Python-Dev] inspect and metaclasses

Antoine Pitrou solipsis at pitrou.net
Fri Sep 6 19:02:47 CEST 2013

On Fri, 06 Sep 2013 08:14:09 -0700
Ethan Furman <ethan at stoneleaf.us> wrote:
> On 09/06/2013 07:47 AM, Armin Rigo wrote:
> >
> > Are you suggesting that inspect.getmro(A) would return (A, object,
> > type)?  That seems very wrong to me.
> Currently, `inspect.getmro(A)` returns `(A, object)`.
> Considering that Python actually will look in A's metaclass to find a class attribute, I think returning `(A, object, 
> type(A)` is appropriate:

No, I don't think it's appropriate at all. You are conflating two
- the instance lookup of an attribute (on A, here)
- the class lookup when the instance lookup fails (on type, here)

Both lookups obey the same MRO rules, it just happens that the
second lookup uses a trivial MRO:

>>> type.__mro__
(<class 'type'>, <class 'object'>)



More information about the Python-Dev mailing list