Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Include/internal/pycore_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ int _PyCompile_EnterScope(struct _PyCompiler *c, identifier name, int scope_type
void *key, int lineno, PyObject *private,
_PyCompile_CodeUnitMetadata *umd);
void _PyCompile_ExitScope(struct _PyCompiler *c);
int _PyCompile_SetQualname(struct _PyCompiler *c);
Py_ssize_t _PyCompile_AddConst(struct _PyCompiler *c, PyObject *o);
_PyInstructionSequence *_PyCompile_InstrSequence(struct _PyCompiler *c);
int _PyCompile_StartAnnotationSetup(struct _PyCompiler *c);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix cleanup on error in ``compiler_set_qualname``. Previously it was called in
``_PyCompile_EnterScope``, after the scope had been enterred, and this was not
reversed in case of an error.
1 change: 1 addition & 0 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ codegen_enter_scope(compiler *c, identifier name, int scope_type,
{
RETURN_IF_ERROR(
_PyCompile_EnterScope(c, name, scope_type, key, lineno, private, umd));
RETURN_IF_ERROR_IN_SCOPE(c, _PyCompile_SetQualname(c));
location loc = LOCATION(lineno, lineno, 0, 0);
if (scope_type == COMPILE_SCOPE_MODULE) {
loc.lineno = 0;
Expand Down
11 changes: 6 additions & 5 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,17 @@ _PyCompile_MaybeAddStaticAttributeToClass(compiler *c, expr_ty e)
return SUCCESS;
}

static int
compiler_set_qualname(compiler *c)
int
_PyCompile_SetQualname(compiler *c)
{
Py_ssize_t stack_size;
struct compiler_unit *u = c->u;
PyObject *name, *base;

if (u->u_scope_type == COMPILE_SCOPE_MODULE) {
return SUCCESS;
}

base = NULL;
stack_size = PyList_GET_SIZE(c->c_stack);
assert(stack_size >= 1);
Expand Down Expand Up @@ -724,9 +728,6 @@ _PyCompile_EnterScope(compiler *c, identifier name, int scope_type,
u->u_private = Py_XNewRef(private);

c->u = u;
if (scope_type != COMPILE_SCOPE_MODULE) {
RETURN_IF_ERROR(compiler_set_qualname(c));
}
return SUCCESS;
}

Expand Down
Loading