Skip to content

Commit 43ac9f5

Browse files
authored
gh-128673: Increase coverage of typing.get_type_hints (#128674)
1 parent ea39c8b commit 43ac9f5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Lib/test/test_typing.py

+19
Original file line numberDiff line numberDiff line change
@@ -7152,6 +7152,25 @@ class C:
71527152
self.assertEqual(get_type_hints(C, format=annotationlib.Format.STRING),
71537153
{'x': 'undefined'})
71547154

7155+
def test_get_type_hints_format_function(self):
7156+
def func(x: undefined) -> undefined: ...
7157+
7158+
# VALUE
7159+
with self.assertRaises(NameError):
7160+
get_type_hints(func)
7161+
with self.assertRaises(NameError):
7162+
get_type_hints(func, format=annotationlib.Format.VALUE)
7163+
7164+
# FORWARDREF
7165+
self.assertEqual(
7166+
get_type_hints(func, format=annotationlib.Format.FORWARDREF),
7167+
{'x': ForwardRef('undefined'), 'return': ForwardRef('undefined')},
7168+
)
7169+
7170+
# STRING
7171+
self.assertEqual(get_type_hints(func, format=annotationlib.Format.STRING),
7172+
{'x': 'undefined', 'return': 'undefined'})
7173+
71557174

71567175
class GetUtilitiesTestCase(TestCase):
71577176
def test_get_origin(self):

0 commit comments

Comments
 (0)