Skip to content

Commit

Permalink
gh-128673: Increase coverage of typing.get_type_hints (#128674)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn authored Jan 9, 2025
1 parent ea39c8b commit 43ac9f5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7152,6 +7152,25 @@ class C:
self.assertEqual(get_type_hints(C, format=annotationlib.Format.STRING),
{'x': 'undefined'})

def test_get_type_hints_format_function(self):
def func(x: undefined) -> undefined: ...

# VALUE
with self.assertRaises(NameError):
get_type_hints(func)
with self.assertRaises(NameError):
get_type_hints(func, format=annotationlib.Format.VALUE)

# FORWARDREF
self.assertEqual(
get_type_hints(func, format=annotationlib.Format.FORWARDREF),
{'x': ForwardRef('undefined'), 'return': ForwardRef('undefined')},
)

# STRING
self.assertEqual(get_type_hints(func, format=annotationlib.Format.STRING),
{'x': 'undefined', 'return': 'undefined'})


class GetUtilitiesTestCase(TestCase):
def test_get_origin(self):
Expand Down

0 comments on commit 43ac9f5

Please sign in to comment.