Skip to content

Commit 65001ef

Browse files
Fix SystemError when compiling __classdict__ class annotation
1 parent 6a0be13 commit 65001ef

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/test/test_type_annotations.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,13 @@ def test_comprehension_in_annotation(self):
485485
ns = run_code("x: [y for y in range(10)]")
486486
self.assertEqual(ns["__annotate__"](1), {"x": list(range(10))})
487487

488+
def test_class_annotation_dunder_classdict(self):
489+
ns = run_code("""
490+
class C:
491+
__classdict__: int
492+
""")
493+
self.assertEqual(ns["C"].__annotations__, {"__classdict__": int})
494+
488495
def test_future_annotations(self):
489496
code = """
490497
from __future__ import annotations
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a :exc:`SystemError` when compiling a compiling ``__classdict__`` class
2+
annotation. Found by OSS-Fuzz in :oss-fuzz:`512907042`.

Python/symtable.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,6 +2870,7 @@ symtable_visit_annotation(struct symtable *st, expr_ty annotation, void *key)
28702870
int future_annotations = st->st_future->ff_features & CO_FUTURE_ANNOTATIONS;
28712871
if (current_type == ClassBlock && !future_annotations) {
28722872
st->st_cur->ste_can_see_class_scope = 1;
2873+
parent_ste->ste_needs_classdict = 1;
28732874
if (!symtable_add_def(st, &_Py_ID(__classdict__), USE, LOCATION(annotation))) {
28742875
return 0;
28752876
}

0 commit comments

Comments
 (0)