diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2023-09-12 00:11:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-12 00:11:06 (GMT) |
commit | b88d9e75f68f102aca45fa62e2b0e2e2ff46d810 (patch) | |
tree | 695c7163a69af069ba074401ac03c3d6582aaa42 /Python/symtable.c | |
parent | 2b1e2f1cd154e6df553eda7936715ea0622b4ecf (diff) | |
download | cpython-b88d9e75f68f102aca45fa62e2b0e2e2ff46d810.zip cpython-b88d9e75f68f102aca45fa62e2b0e2e2ff46d810.tar.gz cpython-b88d9e75f68f102aca45fa62e2b0e2e2ff46d810.tar.bz2 |
gh-109118: Disallow nested scopes within PEP 695 scopes within classes (#109196)
Fixes #109118. Fixes #109194.
Co-authored-by: Carl Meyer <carl@oddbird.net>
Diffstat (limited to 'Python/symtable.c')
-rw-r--r-- | Python/symtable.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Python/symtable.c b/Python/symtable.c index 6c28b49..d737c09 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -2010,6 +2010,17 @@ symtable_visit_expr(struct symtable *st, expr_ty e) VISIT(st, expr, e->v.UnaryOp.operand); break; case Lambda_kind: { + if (st->st_cur->ste_can_see_class_scope) { + // gh-109118 + PyErr_Format(PyExc_SyntaxError, + "Cannot use lambda in annotation scope within class scope"); + PyErr_RangedSyntaxLocationObject(st->st_filename, + e->lineno, + e->col_offset + 1, + e->end_lineno, + e->end_col_offset + 1); + VISIT_QUIT(st, 0); + } if (e->v.Lambda.args->defaults) VISIT_SEQ(st, expr, e->v.Lambda.args->defaults); if (e->v.Lambda.args->kw_defaults) @@ -2459,6 +2470,18 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e, identifier scope_name, asdl_comprehension_seq *generators, expr_ty elt, expr_ty value) { + if (st->st_cur->ste_can_see_class_scope) { + // gh-109118 + PyErr_Format(PyExc_SyntaxError, + "Cannot use comprehension in annotation scope within class scope"); + PyErr_RangedSyntaxLocationObject(st->st_filename, + e->lineno, + e->col_offset + 1, + e->end_lineno, + e->end_col_offset + 1); + VISIT_QUIT(st, 0); + } + int is_generator = (e->kind == GeneratorExp_kind); comprehension_ty outermost = ((comprehension_ty) asdl_seq_GET(generators, 0)); |