Skip to content

Commit

Permalink
Add enum iteration test cases
Browse files Browse the repository at this point in the history
Test cases for python#2305
  • Loading branch information
ngaya-ll committed Feb 2, 2018
1 parent fc2c678 commit 3365669
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test-data/unit/check-enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,45 @@ main:3: error: Revealed type is 'm.F'
main:2: error: Revealed type is 'm.E'
main:3: error: Revealed type is 'm.F'

[case testEnumIteration]
from enum import Enum
class E(Enum):
A = 'a'
l = [e for e in E]
reveal_type(l[0]) # E: Revealed type is '__main__.E'
for e in E:
reveal_type(e) # E: Revealed type is '__main__.E'
[builtins fixtures/list.pyi]

[case testEnumIterable]
from enum import Enum
from typing import Iterable
class E(Enum):
a = 'a'
def f(ie:Iterable[E]):
pass
f(E)

[case testIntEnumIterable]
from enum import IntEnum
from typing import Iterable
class N(IntEnum):
x = 1
def f(ni: Iterable[N]):
pass
def g(ii: Iterable[int]):
pass
f(N)
g(N)

[case testDerivedEnumIterable]
from enum import Enum
from typing import Iterable
class E(str, Enum):
a = 'foo'
def f(ei: Iterable[E]):
pass
def g(si: Iterable[str]):
pass
f(E)
g(E)
42 changes: 42 additions & 0 deletions test-data/unit/pythoneval.test
Original file line number Diff line number Diff line change
Expand Up @@ -1458,3 +1458,45 @@ _testNoCrashOnGenericUnionUnpacking.py:10: error: Revealed type is 'Union[builti
_testNoCrashOnGenericUnionUnpacking.py:11: error: Revealed type is 'Union[builtins.str, builtins.int]'
_testNoCrashOnGenericUnionUnpacking.py:15: error: Revealed type is 'Union[builtins.int*, builtins.str*]'
_testNoCrashOnGenericUnionUnpacking.py:16: error: Revealed type is 'Union[builtins.int*, builtins.str*]'

[case testEnumIteration]
from enum import Enum
class E(Enum):
A = 'a'
l = [e for e in E]
reveal_type(l[0]) # E: Revealed type is '__main__.E'
for e in E:
reveal_type(e) # E: Revealed type is '__main__.E'

[case testEnumIterable]
from enum import Enum
from typing import Iterable
class E(Enum):
a = 'a'
def f(ie:Iterable[E]):
pass
f(E)

[case testIntEnumIterable]
from enum import IntEnum
from typing import Iterable
class N(IntEnum):
x = 1
def f(ni: Iterable[N]):
pass
def g(ii: Iterable[int]):
pass
f(N)
g(N)

[case testDerivedEnumIterable]
from enum import Enum
from typing import Iterable
class E(str, Enum):
a = 'foo'
def f(ei: Iterable[E]):
pass
def g(si: Iterable[str]):
pass
f(E)
g(E)

0 comments on commit 3365669

Please sign in to comment.