8000 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 unittest for new get_type_hints() behaviour on PEP 585 generics w…
…ith forward refs
  • Loading branch information
NiklasRosenstein committed Jan 25, 2022
commit d7f57c7eb10ce94e9b6d32bbab92277e22420d8b
17 changes: 17 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,23 @@ def barfoo(x: AT): ...
def barfoo2(x: CT): ...
self.assertIs(get_type_hints(barfoo2, globals(), locals())['x'], CT)

def test_generic_pep585_forward_ref(self):
# See https://bugs.python.org/issue41370

class N:
a: list['N']
self.assertEqual(
get_type_hints(N, globals(), locals()),
{'a': list[N]}
)

class M:
a: dict['N', list[List[list['M']]]]
self.assertEqual(
get_type_hints(M, globals(), locals()),
{'a': dict[N, list[List[list[M]]]]}
)

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