bpo-41341: Recursive evaluation of ForwardRef in get_type_hints (GH-21553)

The issue raised by recursive evaluation is infinite recursion with
recursive types. In that case, only the first recursive ForwardRef is
evaluated.
(cherry picked from commit 653f420b53)

Co-authored-by: wyfo <joperez@hotmail.fr>
This commit is contained in:
Miss Islington (bot) 2020-07-26 08:31:24 -07:00 committed by GitHub
parent 8b7544cd02
commit 41d1c04f73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 6 deletions

View file

@ -2456,6 +2456,12 @@ class ForwardRefTests(BaseTestCase):
self.assertEqual(get_type_hints(foo, globals(), locals()),
{'a': tuple[T]})
def test_double_forward(self):
def foo(a: 'List[\'int\']'):
pass
self.assertEqual(get_type_hints(foo, globals(), locals()),
{'a': List[int]})
def test_forward_recursion_actually(self):
def namespace1():
a = typing.ForwardRef('A')