From: sobolevn Date: Thu, 9 Jan 2025 14:25:03 +0000 (+0300) Subject: gh-128673: Increase coverage of `typing.get_type_hints` (#128674) X-Git-Tag: v3.14.0a4~57 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=43ac9f505903ba806aa6a5d93e6a67beb04bebc4;p=thirdparty%2FPython%2Fcpython.git gh-128673: Increase coverage of `typing.get_type_hints` (#128674) --- diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 45ba7611059e..1c86b95e8e5c 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -7152,6 +7152,25 @@ class GetTypeHintTests(BaseTestCase): 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):