https://github.com/python/cpython/commit/522fe015ab03903d252d10f94bcd2fca56a521c5
commit: 522fe015ab03903d252d10f94bcd2fca56a521c5
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: StanFromIreland <[email protected]>
date: 2026-06-03T09:39:33+01:00
summary:

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

(cherry picked from commit c52d2b16ddda3995f0f935b1a3815f1aac498da6)

Co-authored-by: Stan Ulbrych <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-05-13-21-26-26.gh-issue-149805.IG6cza.rst
M Lib/test/test_type_annotations.py
M Python/symtable.c

diff --git a/Lib/test/test_type_annotations.py 
b/Lib/test/test_type_annotations.py
index 2a67d63cde66d5a..c98b99e98e9c8e6 100644
--- a/Lib/test/test_type_annotations.py
+++ b/Lib/test/test_type_annotations.py
@@ -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
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
index 000000000000000..02d050840ee1f9b
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-05-13-21-26-26.gh-issue-149805.IG6cza.rst
@@ -0,0 +1,2 @@
+Fix a :exc:`SystemError` when compiling a compiling ``__classdict__`` class
+annotation. Found by OSS-Fuzz in :oss-fuzz:`512907042`.
diff --git a/Python/symtable.c b/Python/symtable.c
index 549ef131388a91e..2ca5b4f38efb776 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -2800,6 +2800,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;
             }

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to