diff options
author | sobolevn <mail@sobolevn.me> | 2025-01-09 14:25:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-09 14:25:03 (GMT) |
commit | 43ac9f505903ba806aa6a5d93e6a67beb04bebc4 (patch) | |
tree | c7b587e72c8e82501182a594360f4bbfb1c3d6b4 | |
parent | ea39c8b08d8f025273bfa5b7a95f7b5984dc1e86 (diff) | |
download | cpython-43ac9f505903ba806aa6a5d93e6a67beb04bebc4.zip cpython-43ac9f505903ba806aa6a5d93e6a67beb04bebc4.tar.gz cpython-43ac9f505903ba806aa6a5d93e6a67beb04bebc4.tar.bz2 |
gh-128673: Increase coverage of `typing.get_type_hints` (#128674)
-rw-r--r-- | Lib/test/test_typing.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 45ba761..1c86b95 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): |