Skip to content

Commit 522fe01

Browse files
[3.14] gh-149805: Fix SystemError when compiling __classdict__ class annotation (GH-149806)
(cherry picked from commit c52d2b1) Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 7756f59 commit 522fe01

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
@@ -2800,6 +2800,7 @@ symtable_visit_annotation(struct symtable *st, expr_ty annotation, void *key)
28002800
int future_annotations = st->st_future->ff_features & CO_FUTURE_ANNOTATIONS;
28012801
if (current_type == ClassBlock && !future_annotations) {
28022802
st->st_cur->ste_can_see_class_scope = 1;
2803+
parent_ste->ste_needs_classdict = 1;
28032804
if (!symtable_add_def(st, &_Py_ID(__classdict__), USE, LOCATION(annotation))) {
28042805
return 0;
28052806
}

0 commit comments

Comments
 (0)