Skip to content

Commit 9e143b2

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

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test-data/unit/pythoneval.test

+45
Original file line numberDiff line numberDiff line change
@@ -1458,3 +1458,48 @@ _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])
1468+
for e in E:
1469+
reveal_type(e)
1470+
[out]
1471+
_testEnumIteration.py:5: error: Revealed type is '_testEnumIteration.E*'
1472+
_testEnumIteration.py:7: error: Revealed type is '_testEnumIteration.E*'
1473+
1474+
[case testEnumIterable]
1475+
from enum import Enum
1476+
from typing import Iterable
1477+
class E(Enum):
1478+
a = 'a'
1479+
def f(ie:Iterable[E]):
1480+
pass
1481+
f(E)
1482+
1483+
[case testIntEnumIterable]
1484+
from enum import IntEnum
1485+
from typing import Iterable
1486+
class N(IntEnum):
1487+
x = 1
1488+
def f(ni: Iterable[N]):
1489+
pass
1490+
def g(ii: Iterable[int]):
1491+
pass
1492+
f(N)
1493+
g(N)
1494+
1495+
[case testDerivedEnumIterable]
1496+
from enum import Enum
1497+
from typing import Iterable
1498+
class E(str, Enum):
1499+
a = 'foo'
1500+
def f(ei: Iterable[E]):
1501+
pass
1502+
def g(si: Iterable[str]):
1503+
pass
1504+
f(E)
1505+
g(E)

0 commit comments

Comments
 (0)