Skip to content

Commit 6a48bbe

Browse files
committed
Add test to actually instantiate class for callable class as an annotate function
1 parent ac888cc commit 6a48bbe

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Lib/test/test_annotationlib.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,25 @@ def annotate(format, /, __Format=Format, __NotImplementedError=NotImplementedErr
15141514

15151515
self.assertEqual(annotations, {"x": int})
15161516

1517+
def test_callable_class_annotate_forwardref_fakeglobals(self):
1518+
# If Format.FORWARDREF is not supported, use Format.VALUE_WITH_FAKE_GLOBALS
1519+
# before falling back to Format.VALUE
1520+
class Annotate(dict):
1521+
def __init__(self, format, /, __Format=Format, __NotImplementedError=NotImplementedError):
1522+
if format == __Format.VALUE:
1523+
super().__init__({'x': str})
1524+
elif format == __Format.VALUE_WITH_FAKE_GLOBALS:
1525+
super().__init__({'x': int})
1526+
else:
1527+
raise __NotImplementedError(format)
1528+
1529+
annotations = annotationlib.call_annotate_function(
1530+
Annotate,
1531+
Format.FORWARDREF
1532+
)
1533+
1534+
self.assertEqual(annotations, {"x": int})
1535+
15171536
def test_user_annotate_forwardref_value_fallback(self):
15181537
# If Format.FORWARDREF and Format.VALUE_WITH_FAKE_GLOBALS are not supported
15191538
# use Format.VALUE

0 commit comments

Comments
 (0)