← index #525PR #3391
Related · high · value 0.109
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

RFC/WIP py/objtype: user classes: Allow to lookup __new__() method.

closedby pfalconopened 2017-10-28updated 2021-05-18

new() method is present by definition in each class, because each class
inherits from "object". But due to effects of multiple inheritance and
subclassing native types, looking it up is tricky: object.new should
be the last choice, if a more specific version is found (in one of multiple
bases, or in native type), that should be used.

This patch implements this behavior by wrapping existing attribute lookup
function, and looking inside "object" only if the otiginal function doesn't
find anything. This relies on "object" not being present explicitly in the
base class chain (otherwise multiple inheritance case will be broken -
object.new will be found while following the very first inheritance
branch, while other branches may have more specific new).

This also leads to additional stack usage on each lookup due to extra
function call.

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