[3.15] gh-149805: Fix SystemError when compiling __classdict__ class annotation (GH-149806)

(cherry picked from commit c52d2b16dd)

Co-authored-by: Stan Ulbrych <stan@python.org>
This commit is contained in:
Miss Islington (bot) 2026-06-03 10:39:22 +02:00 committed by GitHub
parent accc0c8315
commit f8cea98b4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 0 deletions

View file

@ -485,6 +485,13 @@ def test_comprehension_in_annotation(self):
ns = run_code("x: [y for y in range(10)]")
self.assertEqual(ns["__annotate__"](1), {"x": list(range(10))})
def test_class_annotation_dunder_classdict(self):
ns = run_code("""
class C:
__classdict__: int
""")
self.assertEqual(ns["C"].__annotations__, {"__classdict__": int})
def test_future_annotations(self):
code = """
from __future__ import annotations

View file

@ -0,0 +1,2 @@
Fix a :exc:`SystemError` when compiling a compiling ``__classdict__`` class
annotation. Found by OSS-Fuzz in :oss-fuzz:`512907042`.

View file

@ -2870,6 +2870,7 @@ symtable_visit_annotation(struct symtable *st, expr_ty annotation, void *key)
int future_annotations = st->st_future->ff_features & CO_FUTURE_ANNOTATIONS;
if (current_type == ClassBlock && !future_annotations) {
st->st_cur->ste_can_see_class_scope = 1;
parent_ste->ste_needs_classdict = 1;
if (!symtable_add_def(st, &_Py_ID(__classdict__), USE, LOCATION(annotation))) {
return 0;
}