Skip to content

Commit 6e06e01

Browse files
authored
gh-124019: do not call codegen_annotations_in_scope if there are no annotations (#124020)
1 parent a53812d commit 6e06e01

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

Python/codegen.c

+10-14
Original file line numberDiff line numberDiff line change
@@ -1002,26 +1002,22 @@ codegen_annotations(compiler *c, location loc,
10021002
PySTEntryObject *ste;
10031003
RETURN_IF_ERROR(_PySymtable_LookupOptional(SYMTABLE(c), args, &ste));
10041004
assert(ste != NULL);
1005-
bool annotations_used = ste->ste_annotations_used;
10061005

1007-
int err = annotations_used ?
1008-
codegen_setup_annotations_scope(c, loc, (void *)args, ste->ste_name) : SUCCESS;
1009-
Py_DECREF(ste);
1010-
RETURN_IF_ERROR(err);
1011-
1012-
if (codegen_annotations_in_scope(c, loc, args, returns, &annotations_len) < 0) {
1013-
if (annotations_used) {
1014-
_PyCompile_ExitScope(c);
1015-
}
1016-
return ERROR;
1017-
}
1018-
1019-
if (annotations_used) {
1006+
if (ste->ste_annotations_used) {
1007+
int err = codegen_setup_annotations_scope(c, loc, (void *)args, ste->ste_name);
1008+
Py_DECREF(ste);
1009+
RETURN_IF_ERROR(err);
1010+
RETURN_IF_ERROR_IN_SCOPE(
1011+
c, codegen_annotations_in_scope(c, loc, args, returns, &annotations_len)
1012+
);
10201013
RETURN_IF_ERROR(
10211014
codegen_leave_annotations_scope(c, loc, annotations_len)
10221015
);
10231016
return MAKE_FUNCTION_ANNOTATE;
10241017
}
1018+
else {
1019+
Py_DECREF(ste);
1020+
}
10251021

10261022
return 0;
10271023
}

0 commit comments

Comments
 (0)