Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid error when using a TypeVar in a Callable annotation on a variable #930

Open
KotlinIsland opened this issue Dec 6, 2024 · 0 comments
Labels
type checking / linting issues relating to existing diagnostic rules or proposals for new diagnostic rules

Comments

@KotlinIsland
Copy link
Collaborator

KotlinIsland commented Dec 6, 2024

this is an issue with deprecated functionality

from typing import Callable, TypeVar

T = TypeVar("T")
bar: Callable[
       [T],   # Type variable "T" has no meaning in this context reportGeneralTypeIssues
       T,   # Type variable "T" has no meaning in this context reportGeneralTypeIssues
    ] = lambda x: x

reveal_type(bar)

this is deprecated, the new way of doing this is:

class Bar(Protocol):
    def __call__[T](self, t: T, /) -> T: ...

bar: Bar = lambda x: x

which does not present the same error

@KotlinIsland KotlinIsland added the type checking / linting issues relating to existing diagnostic rules or proposals for new diagnostic rules label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type checking / linting issues relating to existing diagnostic rules or proposals for new diagnostic rules
Projects
None yet
Development

No branches or pull requests

1 participant