Skip to content

Using super() in generic classes will fail if the self parameter type is set #697

@Glyphack

Description

@Glyphack

Summary

The following code emits a diagnostic while it looks fine:

class A[T]:
    def f(self: "A", a: T) -> T:
        return a

class B[T](A[T]):
    def f(self: "B", a: T) -> T:
        # `B[Unknown]` is not an instance or subclass of `<class 'B'>` in `super(<class 'B'>, B[Unknown])` call (invalid-super-argument) [Ln 9, Col 16]
        return super().f(a)

playground, while pyright accepts this code.

I also tried annotating self with other types:

With specialized instance: playground
With Self type: playground
(Currently the self type example will not pass even with a non-generic too. But that will be fixed once we have implicit self.)

The problem seems to be in the Specilization::has_relation_to method because it returns false.

Version

9d8cba4 2025-06-25

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggenericsBugs or features relating to ty's generics implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions