Skip to content

Commit 9e4faa4

Browse files
committed
Test get_annotations() on callable class instance
1 parent f752c48 commit 9e4faa4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Lib/test/test_annotationlib.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,26 @@ def __annotate__(self):
11321132
{"x": "int"},
11331133
)
11341134

1135+
def test_non_function_annotate(self):
1136+
class AnnotateCallable:
1137+
def __call__(self, format, /):
1138+
if format > 2:
1139+
raise NotImplementedError
1140+
return {"x": int}
1141+
1142+
class OnlyAnnotate:
1143+
@property
1144+
def __annotate__(self):
1145+
return AnnotateCallable()
1146+
1147+
oa = OnlyAnnotate()
1148+
self.assertEqual(get_annotations(oa, format=Format.VALUE), {"x": int})
1149+
self.assertEqual(get_annotations(oa, format=Format.FORWARDREF), {"x": int})
1150+
self.assertEqual(
1151+
get_annotations(oa, format=Format.STRING),
1152+
{"x": "int"},
1153+
)
1154+
11351155
def test_non_dict_annotate(self):
11361156
class WeirdAnnotate:
11371157
def __annotate__(self, *args, **kwargs):

0 commit comments

Comments
 (0)