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
Make enum type compatible with union of all enum item literals
For example, consider this enum:
```
class E(Enum):
A = 1
B = 1
```
This PR makes `E` compatible with `Literal[E.A, E.B]`.
Also fix mutation of the argument list in
`try_contracting_literals_in_union`.
This fixes some regressions introduced in #9097.
Copy file name to clipboardExpand all lines: test-data/unit/check-enum.test
+16
Original file line number
Diff line number
Diff line change
@@ -1333,3 +1333,19 @@ def f(x: Foo):
1333
1333
reveal_type(x) # N: Revealed type is "Union[Literal[__main__.Foo.B], Literal[__main__.Foo.C]]"
1334
1334
1335
1335
[builtins fixtures/bool.pyi]
1336
+
1337
+
[case testEnumTypeCompatibleWithLiteralUnion]
1338
+
from enum import Enum
1339
+
from typing_extensions import Literal
1340
+
1341
+
class E(Enum):
1342
+
A = 1
1343
+
B = 2
1344
+
C = 3
1345
+
1346
+
e: E
1347
+
a: Literal[E.A, E.B, E.C] = e
1348
+
b: Literal[E.A, E.B] = e # E: Incompatible types in assignment (expression has type "E", variable has type "Union[Literal[E.A], Literal[E.B]]")
1349
+
c: Literal[E.A, E.C] = e # E: Incompatible types in assignment (expression has type "E", variable has type "Union[Literal[E.A], Literal[E.C]]")
1350
+
b = a # E: Incompatible types in assignment (expression has type "Union[Literal[E.A], Literal[E.B], Literal[E.C]]", variable has type "Union[Literal[E.A], Literal[E.B]]")
0 commit comments