mirror of
https://github.com/python/cpython.git
synced 2026-06-28 03:41:13 +00:00
[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:
parent
accc0c8315
commit
f8cea98b4e
3 changed files with 10 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Fix a :exc:`SystemError` when compiling a compiling ``__classdict__`` class
|
||||
annotation. Found by OSS-Fuzz in :oss-fuzz:`512907042`.
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue