Skip to content

Passing self to a generic function that accepts Self #17723

@NeilGirdhar

Description

@NeilGirdhar
from typing import Generic, Self, TypeVar

T = TypeVar('T')


class X(Generic[T]):
    def f(self, t: T) -> None:
        pass


class Y:
    def g(self) -> None:
        X[Self]().f(self)  # error: Argument 1 to "f" of "X" has incompatible type "Y"; expected "Self"  [arg-type]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-self-typesTypes for self

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions