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

Old TypeVar and new [T:] annotations are not equivalent #17749

Closed
jolaf opened this issue Sep 8, 2024 · 4 comments
Closed

Old TypeVar and new [T:] annotations are not equivalent #17749

jolaf opened this issue Sep 8, 2024 · 4 comments
Labels
bug mypy got something wrong

Comments

@jolaf
Copy link
Contributor

jolaf commented Sep 8, 2024

Bug Report

If the same function is defined with old TypeVar syntax in one place and with new [T:] syntax in other place, mypy doesn't consider them equivalent.

To Reproduce

https://mypy-play.net/?mypy=1.11.2&python=3.12&enable-incomplete-feature=NewGenericSyntax&gist=78806d2f754ba0e5ce9bdcb61909fbc6

@jolaf jolaf added the bug mypy got something wrong label Sep 8, 2024
@erictraut
Copy link

Your two examples are different. In one case, you're defining a type variable with an upper bound (Callable[..., Any]) and in the other case, you're omitting the upper bound. Changing your sample to the following eliminates the type error:

    F = TypeVar("F", bound=Callable[..., Any])

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2024
@jolaf
Copy link
Contributor Author

jolaf commented Sep 8, 2024

Your two examples are different

Oh, I see now. Thanks!

But if that is so, it should probably be reflected in the output?

For now, the 'Redefinition' output is just missing, which is definitely wrong (bug number 1).
It becomes visible though if in the newer format type variable name is changed: https://mypy-play.net/?mypy=1.11.2&python=3.12&enable-incomplete-feature=NewGenericSyntax&gist=06224b5d473a6be86cae73f00e4643f1
And it looks like the types being compared are essentially identical, so it's difficult for a user to understand what's wrong and the situation looks like a mypy bug to a user.

For this not to be the case, bound= should be visible in the printout (bug number 2).

Should I file separate issues for these?

@jolaf
Copy link
Contributor Author

jolaf commented Sep 9, 2024

Or should we reopen this one?

@jolaf
Copy link
Contributor Author

jolaf commented Sep 19, 2024

I've filed #17791 and #17792 to note the respective two bugs.

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

No branches or pull requests

3 participants