rope icon indicating copy to clipboard operation
rope copied to clipboard

Rope does not comply with the MRO

Open pchampin opened this issue 11 years ago • 2 comments

When looking for the definition of a method invoked with super, Rope seem to perform a depth-first search in the inheritance graph of the class, while Python actually does a breadth-first search (the so called MRO).

The code below demonstrate the problem:

# diamond inheritance
#
#   A
#  / \
#  B C
#  \ /
#   D

class A(object):
    def method(self):
        return "I'm an A"

class B(A):
    # do not override method
    pass

class C(A):
    def method(self):
        return "I'm a C"

class D(B, C):
    def method(self):
        return super(D, self).method() + " and a D"
        # the super method above is C.method,
        # but rope will send me to A.method
        # when I ask to go to the definition


print D().method()
# will display  "I'm a C and a D"

pchampin avatar Mar 01 '14 14:03 pchampin

@aligrudi any idea about this? Can we somehow visualize the AST tree we get?

mcepl avatar Aug 09 '15 20:08 mcepl

Matěj Cepl [email protected] wrote:

@aligrudi any idea about this? Can we somehow visualize the AST tree we get?

I think it is possible to support MRO; one can start by modifying PyClass._create_concluded_attributes() in pyobjectsdef.py. However, the additional overhead may be very large.

Ali

aligrudi avatar Aug 13 '15 03:08 aligrudi