Skip to content

Commit 7b8b2d0

Browse files
committed
Add enum iteration test cases
Test cases for #2305
1 parent fc2c678 commit 7b8b2d0

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test-data/unit/pythoneval.test

+42
Original file line numberDiff line numberDiff line change
@@ -1458,3 +1458,45 @@ _testNoCrashOnGenericUnionUnpacking.py:10: error: Revealed type is 'Union[builti
14581458
_testNoCrashOnGenericUnionUnpacking.py:11: error: Revealed type is 'Union[builtins.str, builtins.int]'
14591459
_testNoCrashOnGenericUnionUnpacking.py:15: error: Revealed type is 'Union[builtins.int*, builtins.str*]'
14601460
_testNoCrashOnGenericUnionUnpacking.py:16: error: Revealed type is 'Union[builtins.int*, builtins.str*]'
1461+
1462+
[case testEnumIteration]
1463+
from enum import Enum
1464+
class E(Enum):
1465+
A = 'a'
1466+
l = [e for e in E]
1467+
reveal_type(l[0]) # E: Revealed type is '_testEnumIteration.E*'
1468+
for e in E:
1469+
reveal_type(e) # E: Revealed type is '_testEnumIteration.E*'
1470+
1471+
[case testEnumIterable]
1472+
from enum import Enum
1473+
from typing import Iterable
1474+
class E(Enum):
1475+
a = 'a'
1476+
def f(ie:Iterable[E]):
1477+
pass
1478+
f(E)
1479+
1480+
[case testIntEnumIterable]
1481+
from enum import IntEnum
1482+
from typing import Iterable
1483+
class N(IntEnum):
1484+
x = 1
1485+
def f(ni: Iterable[N]):
1486+
pass
1487+
def g(ii: Iterable[int]):
1488+
pass
1489+
f(N)
1490+
g(N)
1491+
1492+
[case testDerivedEnumIterable]
1493+
from enum import Enum
1494+
from typing import Iterable
1495+
class E(str, Enum):
1496+
a = 'foo'
1497+
def f(ei: Iterable[E]):
1498+
pass
1499+
def g(si: Iterable[str]):
1500+
pass
1501+
f(E)
1502+
g(E)

0 commit comments

Comments
 (0)