You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Curiously, it doesn't matter what you put there. For example, this passes:
x: U1[str] =5# ^^^
This doesn't look like a bug to me. U1[str] evaluates to Union[str, int], and it's okay to assign the value 5 to an object that has the type Union[str, int], since 5 is an int.
One might think it passes because T1 is unbound, but even if we bind it (e.g. to float), it still passes:
This one is a bug. However, it's a duplicate of #10445 🙂. It's already been fixed on mypy master; the fix will be included as part of mypy 1.0 (the next release).
If you try the following snippet on mypy master, here is what mypy reports:
fromtypingimportTypeVar, UnionT1=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]
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: