-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Union with TypeVar becomes generic #14258
Comments
This is a feature, not a bug. You've created a generic type alias. The feature is documented here: https://mypy.readthedocs.io/en/stable/generics.html#generic-type-aliases
This doesn't look like a bug to me.
This one is a bug. However, it's a duplicate of #10445 🙂. It's already been fixed on mypy If you try the following snippet on mypy from typing import TypeVar, Union
T1 = TypeVar('T1', bound=float)
U1 = Union[T1, int]
x: U1[str] = 5 # error: Type argument "str" of "U1" must be a subtype of "float" [type-var] |
Thanks for the thorough answer. |
With
disallow_any_generics
, this code:results in
The
U1
type alias becomes generic and has a single argument. Curiously, it doesn't matter what you put there. For example, this passes:One might think it passes because
T1
is unbound, but even if we bind it (e.g. tofloat
), it still passes:Playground:
https://mypy-play.net/?mypy=latest&python=3.11&flags=disallow-any-generics&gist=68115745200d34208786d8267d2d324a
The text was updated successfully, but these errors were encountered: