https://github.com/python/cpython/commit/43ac9f505903ba806aa6a5d93e6a67beb04bebc4
commit: 43ac9f505903ba806aa6a5d93e6a67beb04bebc4
branch: main
author: sobolevn <[email protected]>
committer: sobolevn <[email protected]>
date: 2025-01-09T17:25:03+03:00
summary:
gh-128673: Increase coverage of `typing.get_type_hints` (#128674)
files:
M Lib/test/test_typing.py
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 45ba7611059e43..1c86b95e8e5c29 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -7152,6 +7152,25 @@ class C:
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):
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]