diff options
author | shadchin <shadchin@yandex-team.com> | 2025-06-13 00:05:26 +0300 |
---|---|---|
committer | shadchin <shadchin@yandex-team.com> | 2025-06-13 00:35:30 +0300 |
commit | 796b9088366b10b4cd42885101fc20c0b5709b07 (patch) | |
tree | f287eacb0b95ffd7cabf95b16cafb4788645dc38 /contrib/tools/python3/Python/symtable.c | |
parent | c72bca862651e507d2ff4980ef7f4ff7267a7227 (diff) | |
download | ydb-796b9088366b10b4cd42885101fc20c0b5709b07.tar.gz |
Update Python 3 to 3.12.10
commit_hash:dd2398e159fe1d72ea6b12da52fccc933a41a785
Diffstat (limited to 'contrib/tools/python3/Python/symtable.c')
-rw-r--r-- | contrib/tools/python3/Python/symtable.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/contrib/tools/python3/Python/symtable.c b/contrib/tools/python3/Python/symtable.c index f99ca4fdd06..da17485acdd 100644 --- a/contrib/tools/python3/Python/symtable.c +++ b/contrib/tools/python3/Python/symtable.c @@ -2192,6 +2192,24 @@ symtable_visit_expr(struct symtable *st, expr_ty e) } static int +symtable_visit_type_param_check_reserved_name(struct symtable *st, type_param_ty tp, identifier name) +{ + if (_PyUnicode_Equal(name, &_Py_ID(__classdict__))) { + PyObject *error_msg = PyUnicode_FromFormat("reserved name '%U' cannot be " + "used for type parameter", name); + PyErr_SetObject(PyExc_SyntaxError, error_msg); + Py_DECREF(error_msg); + PyErr_RangedSyntaxLocationObject(st->st_filename, + tp->lineno, + tp->col_offset + 1, + tp->end_lineno, + tp->end_col_offset + 1); + return 0; + } + return 1; +} + +static int symtable_visit_type_param(struct symtable *st, type_param_ty tp) { if (++st->recursion_depth > st->recursion_limit) { @@ -2201,6 +2219,8 @@ symtable_visit_type_param(struct symtable *st, type_param_ty tp) } switch(tp->kind) { case TypeVar_kind: + if (!symtable_visit_type_param_check_reserved_name(st, tp, tp->v.TypeVar.name)) + VISIT_QUIT(st, 0); if (!symtable_add_def(st, tp->v.TypeVar.name, DEF_TYPE_PARAM | DEF_LOCAL, LOCATION(tp))) VISIT_QUIT(st, 0); if (tp->v.TypeVar.bound) { @@ -2219,10 +2239,14 @@ symtable_visit_type_param(struct symtable *st, type_param_ty tp) } break; case TypeVarTuple_kind: + if (!symtable_visit_type_param_check_reserved_name(st, tp, tp->v.TypeVarTuple.name)) + VISIT_QUIT(st, 0); if (!symtable_add_def(st, tp->v.TypeVarTuple.name, DEF_TYPE_PARAM | DEF_LOCAL, LOCATION(tp))) VISIT_QUIT(st, 0); break; case ParamSpec_kind: + if (!symtable_visit_type_param_check_reserved_name(st, tp, tp->v.ParamSpec.name)) + VISIT_QUIT(st, 0); if (!symtable_add_def(st, tp->v.ParamSpec.name, DEF_TYPE_PARAM | DEF_LOCAL, LOCATION(tp))) VISIT_QUIT(st, 0); break; |