Skip to content

Better error messages for some TypeVar init cases #11442

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

Closed
sobolevn opened this issue Nov 3, 2021 · 3 comments · Fixed by #11448
Closed

Better error messages for some TypeVar init cases #11442

sobolevn opened this issue Nov 3, 2021 · 3 comments · Fixed by #11448
Labels
bug mypy got something wrong

Comments

@sobolevn
Copy link
Member

sobolevn commented Nov 3, 2021

While working on #11379 I found several error message that I don't quite understand:

A = TypeVar('A', covariant=False, contravariant=True)
# E: TypeVar 'covariant' may only be 'True'

B = TypeVar('B', covariant=True, contravariant=False)
# E: TypeVar 'contravariant' may only be 'True'

But:

A = TypeVar('A', covariant=True, contravariant=True)
# E: TypeVar cannot be both covariant and contravariant

B = TypeVar('B', covariant=True, contravariant=True)
# E: TypeVar cannot be both covariant and contravariant
@sobolevn sobolevn added the bug mypy got something wrong label Nov 3, 2021
@sobolevn
Copy link
Member Author

sobolevn commented Nov 3, 2021

Btw, this message is not tested.

@sobolevn
Copy link
Member Author

sobolevn commented Nov 3, 2021

I think that I am going to change the logic a bit as well. Because this is valid python:

>>> from typing import TypeVar
>>> A = TypeVar('A', contravariant=False)

No need to forbid that 👍

@sobolevn
Copy link
Member Author

Thanks for the merge 😊

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

Successfully merging a pull request may close this issue.

1 participant