Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added testcases for pep585ga #1

Merged
merged 9 commits into from
Oct 24, 2020
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]