Skip to content

invalid-argument-type for annotated self argument when a generic context exists #1131

@Glyphack

Description

@Glyphack

This came up as part of astral-sh/ruff#18007. Since it can be reproduced on main I created a separate issue & PR to check ecosystem changes.

Normally annotated self accepts instance of that class a valid argument:

from typing import Self

class C:
    def m(self: Self, x: int) -> None: ...

c: C = C()
c.m(1)

But if the method has generics then this would not work:

from typing import Self
class C:
    def m[S](self: Self, x: S) -> None: ...

c: C[int] = C()
# error: [invalid-argument-type] "Argument to bound method `m` is incorrect: Expected `Self@m`, found `C`"
c.m(1)

Metadata

Metadata

Assignees

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