10000 Fix up qualnames · python/cpython@b9d8fbb · GitHub
[go: up one dir, main page]

Skip to content

Commit b9d8fbb

Browse files
committed
Fix up qualnames
1 parent 5521c7d commit b9d8fbb

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Python/compile.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ enum {
196196
COMPILER_SCOPE_ASYNC_FUNCTION,
197197
COMPILER_SCOPE_LAMBDA,
198198
COMPILER_SCOPE_COMPREHENSION,
199+
COMPILER_SCOPE_TYPEPARAMS,
199200
};
200201

201202
typedef struct {
@@ -780,6 +781,19 @@ compiler_set_qualname(struct compiler *c)
780781
capsule = PyList_GET_ITEM(c->c_stack, stack_size - 1);
781782
parent = (struct compiler_unit *)PyCapsule_GetPointer(capsule, CAPSULE_NAME);
782783
assert(parent);
784+
if (parent->u_scope_type == COMPILER_SCOPE_TYPEPARAMS) {
785+
/* The parent is a type parameter scope, so we need to
786+
look at the grandparent. */
787+
if (stack_size == 2) {
788+
// If we're immediately within the module, we can skip
789+
// the rest and just set the qualname to be the same as name.
790+
u->u_qualname = Py_NewRef(u->u_name);
791+
return SUCCESS;
792+
}
793+
capsule = PyList_GET_ITEM(c->c_stack, stack_size - 2);
794+
parent = (struct compiler_unit *)PyCapsule_GetPointer(capsule, CAPSULE_NAME);
795+
assert(parent);
796+
}
783797

784798
if (u->u_scope_type == COMPILER_SCOPE_FUNCTION
785799
|| u->u_scope_type == COMPILER_SCOPE_ASYNC_FUNCTION
@@ -2242,7 +2256,7 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
22422256
if (!typeparams_name) {
22432257
return ERROR;
22442258
}
2245-
if (compiler_enter_scope(c, typeparams_name, COMPILER_SCOPE_FUNCTION,
2259+
if (compiler_enter_scope(c, typeparams_name, COMPILER_SCOPE_TYPEPARAMS,
22462260
(void *)typeparams, firstlineno) == -1) {
22472261
Py_DECREF(typeparams_name);
22482262
return ERROR;
@@ -2355,7 +2369,7 @@ compiler_class(struct compiler *c, stmt_ty s)
23552369
if (!typeparams_name) {
23562370
return ERROR;
23572371
}
2358-
if (compiler_enter_scope(c, typeparams_name, COMPILER_SCOPE_FUNCTION,
2372+
if (compiler_enter_scope(c, typeparams_name, COMPILER_SCOPE_TYPEPARAMS,
23592373
(void *)typeparams, firstlineno) == -1) {
23602374
Py_DECREF(typeparams_name);
23612375
return ERROR;

0 commit comments

Comments
 (0)
0