Skip to content

Commit

Permalink
pythongh-124019: do not call codegen_annotations_in_scope if there ar…
Browse files Browse the repository at this point in the history
…e no annotations (python#124020)
  • Loading branch information
iritkatriel authored Sep 12, 2024
1 parent a53812d commit 6e06e01
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1002,26 +1002,22 @@ codegen_annotations(compiler *c, location loc,
PySTEntryObject *ste;
RETURN_IF_ERROR(_PySymtable_LookupOptional(SYMTABLE(c), args, &ste));
assert(ste != NULL);
bool annotations_used = ste->ste_annotations_used;

int err = annotations_used ?
codegen_setup_annotations_scope(c, loc, (void *)args, ste->ste_name) : SUCCESS;
Py_DECREF(ste);
RETURN_IF_ERROR(err);

if (codegen_annotations_in_scope(c, loc, args, returns, &annotations_len) < 0) {
if (annotations_used) {
_PyCompile_ExitScope(c);
}
return ERROR;
}

if (annotations_used) {
if (ste->ste_annotations_used) {
int err = codegen_setup_annotations_scope(c, loc, (void *)args, ste->ste_name);
Py_DECREF(ste);
RETURN_IF_ERROR(err);
RETURN_IF_ERROR_IN_SCOPE(
c, codegen_annotations_in_scope(c, loc, args, returns, &annotations_len)
);
RETURN_IF_ERROR(
codegen_leave_annotations_scope(c, loc, annotations_len)
);
return MAKE_FUNCTION_ANNOTATE;
}
else {
Py_DECREF(ste);
}

return 0;
}
Expand Down

0 comments on commit 6e06e01

Please sign in to comment.