Skip to content

Incorrect bound method signature involving Self #1713

@ibraheemdev

Description

@ibraheemdev

Summary

from typing import Self, reveal_type

class Foo[T]:
    def foo(self) -> T:
        raise NotImplementedError

class Bar:
    def _(self, x: Foo[Self]):
        reveal_type(x.foo)  # revealed: bound method Foo[Self@_].foo() -> Foo[Self@_]

def f[T: Bar](x: Foo[T]):
    reveal_type(x.foo)  # revealed: bound method Foo[T@f].foo() -> T@f

The return type of the first is incorrect.

Originally found in astral-sh/ruff#21685 (comment). I bisected this to astral-sh/ruff#20677.

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions