Skip to content

Generic class with typevar inheriting from other class does not resolve super().__init__() call for go to definition #2854

@OlavMSG

Description

@OlavMSG

Summary

In VS code when using the F12 go to definition feature.

Example:

class Base:
    def __init__(self, x: int) -> None:
        self.x = x
        print("Base init")


class Generic[T](Base):
    def __init__(self, x: int, y: T):
        # Definition does not resolve to Base.__init__ but super.__init__ using ty,
        # Pylance resolves to Base.__init__
        super().__init__(x) 
        self.y = y
        print("Generic init")

if __name__ == "__main__":

    a = Generic[float](1, 2.3)
    # prints
    # Base init
    # Generic init
    # x=1, y=2.3
    print(f"x={a.x}, y={a.y}")

The super().__init__() call resolves to super.__init__ when using ty.
Switching to Pylance resolves the problem and it resolves to Base.__init__.

It may be wort noting that hovering over the super().__init__(x) displays a "@todo"

Version

ty 0.0.17

Metadata

Metadata

Assignees

No one assigned

    Labels

    serverRelated to the LSP server

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions