]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-149805: Fix `SystemError` when compiling `__classdict__` class annotation (#149806)
authorStan Ulbrych <stan@python.org>
Tue, 2 Jun 2026 09:17:03 +0000 (10:17 +0100)
committerGitHub <noreply@github.com>
Tue, 2 Jun 2026 09:17:03 +0000 (10:17 +0100)
Lib/test/test_type_annotations.py
Misc/NEWS.d/next/Core_and_Builtins/2026-05-13-21-26-26.gh-issue-149805.IG6cza.rst [new file with mode: 0644]
Python/symtable.c

index d459f497e333e645b23950fb7cfc2edc02f42cb7..b751f825bb97d594d2cce5bae29a6aba8081c97d 100644 (file)
@@ -485,6 +485,13 @@ class DeferredEvaluationTests(unittest.TestCase):
         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
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-05-13-21-26-26.gh-issue-149805.IG6cza.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-05-13-21-26-26.gh-issue-149805.IG6cza.rst
new file mode 100644 (file)
index 0000000..02d0508
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a :exc:`SystemError` when compiling a compiling ``__classdict__`` class
+annotation. Found by OSS-Fuzz in :oss-fuzz:`512907042`.
index 14d7ce91b6283547e6ee9c378bf08c30e5e39f87..070e374101b5cd5632cf28fe089ffd7d2388d319 100644 (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;
             }