gh-137814: Fix __qualname__ of __annotate__ (#137842)

This commit is contained in:
Jelle Zijlstra 2026-04-15 21:52:30 -07:00 committed by GitHub
parent 54607eec34
commit 5b8cd314e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 38 additions and 1 deletions

View file

@ -297,6 +297,19 @@ compiler_set_qualname(compiler *c)
base = Py_NewRef(parent->u_metadata.u_qualname);
}
}
if (u->u_ste->ste_function_name != NULL) {
PyObject *tmp = base;
base = PyUnicode_FromFormat("%U.%U",
base,
u->u_ste->ste_function_name);
Py_DECREF(tmp);
if (base == NULL) {
return ERROR;
}
}
}
else if (u->u_ste->ste_function_name != NULL) {
base = Py_NewRef(u->u_ste->ste_function_name);
}
if (base != NULL) {

View file

@ -108,6 +108,7 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
ste->ste_id = k; /* ste owns reference to k */
ste->ste_name = Py_NewRef(name);
ste->ste_function_name = NULL;
ste->ste_symbols = NULL;
ste->ste_varnames = NULL;
@ -186,6 +187,7 @@ ste_dealloc(PyObject *op)
ste->ste_table = NULL;
Py_XDECREF(ste->ste_id);
Py_XDECREF(ste->ste_name);
Py_XDECREF(ste->ste_function_name);
Py_XDECREF(ste->ste_symbols);
Py_XDECREF(ste->ste_varnames);
Py_XDECREF(ste->ste_children);
@ -2918,6 +2920,7 @@ symtable_visit_annotations(struct symtable *st, stmt_ty o, arguments_ty a, expr_
(void *)a, LOCATION(o))) {
return 0;
}
Py_XSETREF(st->st_cur->ste_function_name, Py_NewRef(function_ste->ste_name));
if (is_in_class || current_type == ClassBlock) {
st->st_cur->ste_can_see_class_scope = 1;
if (!symtable_add_def(st, &_Py_ID(__classdict__), USE, LOCATION(o))) {