Skip to content

Commit 8e65065

Browse files
committed
gh-132285: Add a test when __annotations__ is deleted
1 parent 0e4cf9c commit 8e65065

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎Lib/test/test_annotationlib.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,36 @@ def f(x: int):
809809
{"x": "int"},
810810
)
811811

812+
def test_del_annotations(self):
813+
# gh-132285
814+
called = False
815+
class A:
816+
def __annotate__(format):
817+
nonlocal called
818+
called = True
819+
return {'a': int}
820+
821+
for format in Format:
822+
if format == Format.VALUE_WITH_FAKE_GLOBALS:
823+
continue
824+
825+
called = False
826+
with self.subTest(format=format):
827+
self.assertEqual(
828+
annotationlib.get_annotations(A, format=format),
829+
{'a': int},
830+
)
831+
self.assertTrue(called)
832+
833+
del A.__annotations__
834+
called = False
835+
836+
self.assertEqual(
837+
annotationlib.get_annotations(A, format=format),
838+
{'a': int},
839+
)
840+
self.assertTrue(called)
841+
812842
def test_non_dict_annotations(self):
813843
class WeirdAnnotations:
814844
@property

0 commit comments

Comments
 (0)