Skip to content

Commit

Permalink
Merge pull request #1 from cdce8p/pep585-tests
Browse files Browse the repository at this point in the history
Added testcases for pep585ga
  • Loading branch information
AllanDaemon committed Oct 24, 2020
2 parents 40b2da3 + 8a17cf9 commit 8ca6130
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions mypy/test/testcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
'check-errorcodes.test',
'check-annotated.test',
'check-parameter-specification.test',
'check-generic-alias.test',
]

# Tests that use Python 3.8-only AST features (like expression-scoped ignores):
Expand Down
3 changes: 2 additions & 1 deletion mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ def try_analyze_special_unbound_type(self, t: UnboundType, fullname: str) -> Opt
elif fullname == 'typing.Callable':
return self.analyze_callable_type(t)
elif (fullname == 'typing.Type' or
(fullname == 'builtins.type' and self.api.is_future_flag_set('annotations'))):
(fullname == 'builtins.type' and self.api.is_future_flag_set('annotations')) or
(fullname == 'builtins.type' and not self.options.python_version < (3, 9))):
if len(t.args) == 0:
if fullname == 'typing.Type':
any_type = self.get_omitted_any(t)
Expand Down
49 changes: 49 additions & 0 deletions test-data/unit/check-generic-alias.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-- Test cases for generic aliases

[case testGenericAliasImportCollections]
# flags: --python-version 3.9
from collections import defaultdict, OrderedDict, ChainMap, Counter, deque

t1: defaultdict[int, int]
t2: OrderedDict[int, int]
t3: ChainMap[int, int]
t4: Counter[int]
t5: deque[int]

[builtins fixtures/tuple.pyi]

[case testGenericAliasImportCollectionsABC]
# flags: --python-version 3.9
from collections.abc import Awaitable, Coroutine, Iterable, Iterator, Mapping

t1: Awaitable
t2: Coroutine
t3: Iterable
t4: Iterator
t5: Mapping

[builtins fixtures/tuple.pyi]

[case testGenericAliasImportBuiltIns]
# flags: --python-version 3.9

t1: type[int]

[builtins fixtures/list.pyi]
[builtins fixtures/dict.pyi]

[case testGenericAliasImportBuiltInsSet]
# flags: --python-version 3.9

t1: set[int]

[builtins fixtures/set.pyi]

[case testGenericAliasImportRe]
# flags: --python-version 3.9
from re import Pattern, Match

t1: Pattern[str]
t2: Match[str]

[builtins fixtures/tuple.pyi]

0 comments on commit 8ca6130

Please sign in to comment.