pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Show Type Hierarchy doesn't show subtypes

Open StellaHuang95 opened this issue 2 years ago • 4 comments

Code Snippet

class Base:
    def method(self):
        pass

class Derived(Base):
    def method(self):
        return super().method()
    
class Derived2(Base):
    def method(self):
        return super().method()
    
class Derived3(Derived, Derived2):
    def method(self):
        return super().method()

c = Derived2()
c.method()

Repro Steps

  1. place cursor on Derived2 and see type hierarchy, check subtypes and supertypes

Expected behavior

Both subtypes and supertypes are shown correctly. Specifically, when I click on c.method(), I expect it to show method in Derived3 as its subtype.

Actual behavior

No subtypes are shown.

StellaHuang95 avatar Jan 25 '24 23:01 StellaHuang95

Isn't this behavior (showing sub vs. super types) dependent on this toggle button?

image

image

debonte avatar Jan 25 '24 23:01 debonte

@debonte yes, this is the show type hierarchy feature, not the show call hierarchy. Show type hierarchy is supposed to show both overriding method and overriden method, so in this case, I am expecting method in Derived3 to be shown as c.method's subtype. image

StellaHuang95 avatar Jan 25 '24 23:01 StellaHuang95

Is that how it's supposed to work? Given that Derived2.method isn't a type, I wouldn't expect it to show overriding methods as subtypes. Maybe the bug here is that we shouldn't allow "Show Type Hierarchy" on non-type symbols?

debonte avatar Jan 25 '24 23:01 debonte

Good point, this is just my interpretation of this pr.

@heejaechang might know it better. Regardless, I was expecting show supertype and subtype to behave consistently.

StellaHuang95 avatar Jan 26 '24 00:01 StellaHuang95