]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-128673: Increase coverage of `typing.get_type_hints` (#128674)
authorsobolevn <mail@sobolevn.me>
Thu, 9 Jan 2025 14:25:03 +0000 (17:25 +0300)
committerGitHub <noreply@github.com>
Thu, 9 Jan 2025 14:25:03 +0000 (17:25 +0300)
Lib/test/test_typing.py

index 45ba7611059e43707c0a5638228a2e886450bc4d..1c86b95e8e5c29540e8f511bd82296ee163197d5 100644 (file)
@@ -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):