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

Cannot declare the type of a type variable #7233

Closed
jaswilli opened this issue Jul 17, 2019 · 4 comments
Closed

Cannot declare the type of a type variable #7233

jaswilli opened this issue Jul 17, 2019 · 4 comments

Comments

@jaswilli
Copy link

After updating a project to version 0.720 I'm encountering a new error triggered by applying Final (from typing_extensions) to a TypeVar. A reproduction is below:

from typing import TypeVar
from typing_extensions import Final

# ok
MyType1 = TypeVar("MyType1")

# not ok
MyType2: Final = TypeVar("MyType2")

output:

repro.py:8: error: Cannot declare the type of a type variable
repro.py:8: error: "object" not callable
  • mypy version: 0.720
  • python version: 3.7.4
  • Do you see the same issue after installing mypy from Git master?

Yes (mypy-0.730+dev.b405e05e220935dca6aa895045924ee68b435091)

@JelleZijlstra
Copy link
Member

What would be the point of adding Final to a TypeVar assignment? Mypy already disallows assigning to MyType2.

@jaswilli
Copy link
Author

What would be the point of adding Final to a TypeVar assignment? Mypy already disallows assigning to MyType2.

I didn't realize it was already disallowed by mypy, that's good to know. I simply annotated the TypeVars as Final because it seemed like a reasonable thing to do and then when I upgraded to 0.720 I got the error.

If the new behavior is actually correct and desired then feel free to close this issue.

@JelleZijlstra
Copy link
Member

OK, I think the old behavior of accepting final was probably just an accident, but leaving to @msullivan or @ilevkivskyi (authors of the Final PEP) to close this.

@ilevkivskyi
Copy link
Member

Yes, type variables are always implicitly final. The error message is poor, but we already have #1573 to track bad error messages for invalid type variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants