mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
gh-124206: Fix calling get_annotate_function() on static types (#124208)
Fixes #124206. No news entry because the bug this fixes was never released.
This commit is contained in:
parent
3b6bfa77aa
commit
96f619faa7
3 changed files with 45 additions and 1 deletions
|
@ -7043,6 +7043,25 @@ class GetTypeHintTests(BaseTestCase):
|
|||
self.assertEqual(get_type_hints(g), {'x': collections.abc.Callable[..., int]})
|
||||
self.assertEqual(get_type_hints(h), {'x': collections.abc.Callable[P, int]})
|
||||
|
||||
def test_get_type_hints_format(self):
|
||||
class C:
|
||||
x: undefined
|
||||
|
||||
with self.assertRaises(NameError):
|
||||
get_type_hints(C)
|
||||
|
||||
with self.assertRaises(NameError):
|
||||
get_type_hints(C, format=annotationlib.Format.VALUE)
|
||||
|
||||
annos = get_type_hints(C, format=annotationlib.Format.FORWARDREF)
|
||||
self.assertIsInstance(annos, dict)
|
||||
self.assertEqual(list(annos), ['x'])
|
||||
self.assertIsInstance(annos['x'], annotationlib.ForwardRef)
|
||||
self.assertEqual(annos['x'].__arg__, 'undefined')
|
||||
|
||||
self.assertEqual(get_type_hints(C, format=annotationlib.Format.SOURCE),
|
||||
{'x': 'undefined'})
|
||||
|
||||
|
||||
class GetUtilitiesTestCase(TestCase):
|
||||
def test_get_origin(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue