Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Lib/test/test_type_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a :exc:`SystemError` when compiling a compiling ``__classdict__`` class
annotation. Found by OSS-Fuzz in :oss-fuzz:`512907042`.
1 change: 1 addition & 0 deletions Python/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading