← index #525PR #5139
Off-topic · high · value 0.105
QUERY · ISSUE

Method Resolution Order (MRO) is not compliant

openby pfalconopened 2014-04-28updated 2024-08-28
py-core

uPy currently implements depth-first MRO, which is equivalent to one used pre-Python2.2.
References:

  • http://python-history.blogspot.com/2010/06/method-resolution-order.html
  • https://www.python.org/download/releases/2.3/mro/
CANDIDATE · PULL REQUEST

py/objtype: Add type.__bases__ attribute.

closedby nevercastopened 2019-09-24updated 2019-10-18
py-core

Proposal: Add __bases__ attribute to types so that the inheritance heirachy can be inspected. Related to #5106 and #4368

I have not implemented .__base__ nor have I made any changes to anything MRO related. This is simply a read-only attribute that supports single and multiple inheritance.

For me, the intent of this addition is so I can type check objects in my application to ensure they inherit from a common base class.

It should be noted that I would like to add documentation and tests for this, once we finalize the draft. I'm not proposing we ignore housekeeping.

Example:

>>> class A:
...     pass
>>> class B(object):
...     pass
>>> class C(B):
...     pass
>>> class D(C, A):
...     pass
>>> A.__bases__
(<class 'object'>,)
>>> B.__bases__
(<class 'object'>,)
>>> C.__bases__
(<class 'B'>,)
>>> D.__bases__
(<class 'C'>, <class 'A'>)

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied