Skip to content

(🐞) Explicit type parameter specification with method reference screws up assignability #13041

Closed
@KotlinIsland

Description

@KotlinIsland
from typing import _T as T, Callable, Generic, TypeVar

class A(Generic[T]):
    def f(self) -> None: ...

c: Callable[[A[int]], None]
c = A.f
c = A[int].f  # error: Incompatible types in assignment (expression has type "(A[T]) -> None", variable has type "(A[int]) -> None") 

expression has type "(A[T]) -> None"

Uhhhh, I don't think it does...

Mypy in Real Life

class B(A[int]): ...

# some higher order method
foo(list_of_b, B.f)  # error

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions