From 43ac9f505903ba806aa6a5d93e6a67beb04bebc4 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 9 Jan 2025 17:25:03 +0300 Subject: gh-128673: Increase coverage of `typing.get_type_hints` (#128674) --- Lib/test/test_typing.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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): -- cgit v0.12