summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2024-05-28 02:50:38 (GMT)
committerGitHub <noreply@github.com>2024-05-28 02:50:38 (GMT)
commita9a74da4a0ca0645f049e67b6434a95e30592c32 (patch)
tree99d8fd8e532ed3cd955e41acacbfd4a65bfa3f5e /Python/compile.c
parent3e8b60905e97a4fe89bb24180063732214368938 (diff)
downloadcpython-a9a74da4a0ca0645f049e67b6434a95e30592c32.zip
cpython-a9a74da4a0ca0645f049e67b6434a95e30592c32.tar.gz
cpython-a9a74da4a0ca0645f049e67b6434a95e30592c32.tar.bz2
gh-119311: Fix name mangling with PEP 695 generic classes (#119464)
Fixes #119311. Fixes #119395.
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 6dacfc7..cdc5b26 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1001,7 +1001,7 @@ static int
compiler_addop_name(struct compiler_unit *u, location loc,
int opcode, PyObject *dict, PyObject *o)
{
- PyObject *mangled = _Py_Mangle(u->u_private, o);
+ PyObject *mangled = _Py_MaybeMangle(u->u_private, u->u_ste, o);
if (!mangled) {
return ERROR;
}
@@ -1873,7 +1873,7 @@ compiler_visit_kwonlydefaults(struct compiler *c, location loc,
arg_ty arg = asdl_seq_GET(kwonlyargs, i);
expr_ty default_ = asdl_seq_GET(kw_defaults, i);
if (default_) {
- PyObject *mangled = _Py_Mangle(c->u->u_private, arg->arg);
+ PyObject *mangled = _Py_MaybeMangle(c->u->u_private, c->u->u_ste, arg->arg);
if (!mangled) {
goto error;
}
@@ -1930,7 +1930,7 @@ compiler_visit_argannotation(struct compiler *c, identifier id,
if (!annotation) {
return SUCCESS;
}
- PyObject *mangled = _Py_Mangle(c->u->u_private, id);
+ PyObject *mangled = _Py_MaybeMangle(c->u->u_private, c->u->u_ste, id);
if (!mangled) {
return ERROR;
}
@@ -2625,7 +2625,6 @@ compiler_class(struct compiler *c, stmt_ty s)
asdl_type_param_seq *type_params = s->v.ClassDef.type_params;
int is_generic = asdl_seq_LEN(type_params) > 0;
if (is_generic) {
- Py_XSETREF(c->u->u_private, Py_NewRef(s->v.ClassDef.name));
PyObject *type_params_name = PyUnicode_FromFormat("<generic parameters of %U>",
s->v.ClassDef.name);
if (!type_params_name) {
@@ -2637,6 +2636,7 @@ compiler_class(struct compiler *c, stmt_ty s)
return ERROR;
}
Py_DECREF(type_params_name);
+ Py_XSETREF(c->u->u_private, Py_NewRef(s->v.ClassDef.name));
RETURN_IF_ERROR_IN_SCOPE(c, compiler_type_params(c, type_params));
_Py_DECLARE_STR(type_params, ".type_params");
RETURN_IF_ERROR_IN_SCOPE(c, compiler_nameop(c, loc, &_Py_STR(type_params), Store));
@@ -4203,7 +4203,7 @@ compiler_nameop(struct compiler *c, location loc,
return ERROR;
}
- mangled = _Py_Mangle(c->u->u_private, name);
+ mangled = _Py_MaybeMangle(c->u->u_private, c->u->u_ste, name);
if (!mangled) {
return ERROR;
}
@@ -6512,7 +6512,7 @@ compiler_annassign(struct compiler *c, stmt_ty s)
VISIT(c, expr, s->v.AnnAssign.annotation);
}
ADDOP_NAME(c, loc, LOAD_NAME, &_Py_ID(__annotations__), names);
- mangled = _Py_Mangle(c->u->u_private, targ->v.Name.id);
+ mangled = _Py_MaybeMangle(c->u->u_private, c->u->u_ste, targ->v.Name.id);
ADDOP_LOAD_CONST_NEW(c, loc, mangled);
ADDOP(c, loc, STORE_SUBSCR);
}