10000 bpo-41370: Evaluate strings as forward refs in PEP 585 generics by NiklasRosenstein · Pull Request #30900 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-41370: Evaluate strings as forward refs in PEP 585 generics #30900

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

Merged
merged 10 commits into from
Mar 7, 2022
Merged
Prev Previous commit
Next Next commit
add test for recursive type
  • Loading branch information
NiklasRosenstein committed Jan 27, 2022
commit a04bd5d8867f71f0ba2497a0ef65f8d8b8833959
10 changes: 9 additions & 1 deletion Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2024,20 +2024,28 @@ class C2:
{'a': dict[C1, list[List[list[C2]]]]}
)

# Test stringified annotations
scope = {}
exec(textwrap.dedent('''
from __future__ import annotations
class C3:
a: List[list["C2"]]
'''), scope)
C3 = scope['C3']

self.assertEqual(C3.__annotations__['a'], "List[list['C2']]")
self.assertEqual(
get_type_hints(C3, globals(), locals()),
{'a': List[list[C2]]}
)

# Test recursive types
X = list["X"]
def f(x: X): ...
self.assertEqual(
get_type_hints(f, globals(), locals()),
{'x': list[list[ForwardRef('X')]]}
)

def test_extended_generic_rules_subclassing(self):
class T1(Tuple[T, KT]): ...
class T2(Tuple[T, ...]): ...
Expand Down
0