Questions tagged [python-mro]

Method Resolution Order (MRO) defines the class search path used by Python to search for the right method to use in classes having multi-inheritance.

Method Resolution Order defines the class search path used by Python to search for the right method to use in classes having multi-inheritance.

4 questions
9
votes
2 answers

Weird MRO result when inheriting directly from typing.NamedTuple

I am confused why FooBar.__mro__ doesn't show like the above two. I still don't know why after some digging into the CPython source code. from typing import NamedTuple from collections import namedtuple A = namedtuple('A',…
4
votes
3 answers

Method resolution order in Python

I am new to Python. I am using Python 2.7. I was going through method order resolution with a small snippet as follows: class A(object): attr = 'A' class B(A): pass class C(A): attr = 'C' class D(B,C): pass x = D() print…
Manu
  • 103
  • 6
1
vote
2 answers

Dynamic/static analysis of method resolution order in Python

Is there a way that I can pragmatically determine, either at runtime, or via static analysis, the method resolution order for a given python class? Imagine I have a set of classes class A(): ... class B(A): ... class C(A): ... class…
timthelion
  • 2,636
  • 2
  • 21
  • 30
1
vote
1 answer

Any difference in adding grandparent into MRO in python?

Are there any side-effects of adding grandparent to the MRO? Purpose is I would like to get grandchildren classes by using grandparent.__subclasses__() class A(object): def work(self): print 'A' class B(A): def work(self): …
James Lin
  • 25,028
  • 36
  • 133
  • 233