Skip to content

Commit dad4799

Browse files
committed
reduce diff, revert error
1 parent e2b6368 commit dad4799

File tree

1 file changed

+45
-44
lines changed

1 file changed

+45
-44
lines changed

Python/compile.c

+45-44
Original file line numberDiff line numberDiff line change
@@ -2007,9 +2007,8 @@ compiler_unwind_fblock(struct compiler *c, location *ploc,
20072007
/* This POP_BLOCK gets the line number of the unwinding statement */
20082008
ADDOP(c, *ploc, POP_BLOCK);
20092009
if (preserve_tos) {
2010-
if (compiler_push_fblock(c, *ploc, POP_VALUE, NO_LABEL, NO_LABEL, NULL) < 0) {
2011-
return ERROR;
2012-
}
2010+
RETURN_IF_ERROR(
2011+
compiler_push_fblock(c, *ploc, POP_VALUE, NO_LABEL, NO_LABEL, NULL));
20132012
}
20142013
/* Emit the finally block */
20152014
VISIT_SEQ(c, stmt, info->fb_datum);
@@ -2041,9 +2040,7 @@ compiler_unwind_fblock(struct compiler *c, location *ploc,
20412040
if (preserve_tos) {
20422041
ADDOP_I(c, *ploc, SWAP, 2);
20432042
}
2044-
if (compiler_call_exit_with_nones(c, *ploc) < 0) {
2045-
return ERROR;
2046-
}
2043+
RETURN_IF_ERROR(compiler_call_exit_with_nones(c, *ploc));
20472044
if (info->fb_type == ASYNC_WITH) {
20482045
ADDOP_I(c, *ploc, GET_AWAITABLE, 2);
20492046
ADDOP_LOAD_CONST(c, *ploc, Py_None);
@@ -2093,8 +2090,8 @@ compiler_unwind_fblock_stack(struct compiler *c, location *ploc,
20932090
}
20942091
struct fblockinfo *top = &c->u->u_fblock[c->u->u_nfblocks-1];
20952092
if (top->fb_type == EXCEPTION_GROUP_HANDLER) {
2096-
return compiler_error(c, *ploc,
2097-
"'break', 'continue' and 'return' cannot appear in an except* block");
2093+
return compiler_error(
2094+
c, *ploc, "'break', 'continue' and 'return' cannot appear in an except* block");
20982095
}
20992096
if (loop != NULL && (top->fb_type == WHILE_LOOP || top->fb_type == FOR_LOOP)) {
21002097
*loop = top;
@@ -2353,7 +2350,9 @@ compiler_visit_kwonlydefaults(struct compiler *c, location loc,
23532350
goto error;
23542351
}
23552352
}
2356-
RETURN_IF_ERROR(compiler_visit_expr(c, default_));
2353+
if (compiler_visit_expr(c, default_) < 0) {
2354+
goto error;
2355+
}
23572356
}
23582357
}
23592358
if (keys != NULL) {
@@ -2445,26 +2444,30 @@ compiler_visit_annotations(struct compiler *c, location loc,
24452444
*/
24462445
Py_ssize_t annotations_len = 0;
24472446

2448-
if (compiler_visit_argannotations(c, args->args, &annotations_len, loc) < 0)
2449-
return ERROR;
2450-
if (compiler_visit_argannotations(c, args->posonlyargs, &annotations_len, loc) < 0)
2451-
return ERROR;
2452-
if (args->vararg && args->vararg->annotation &&
2453-
compiler_visit_argannotation(c, args->vararg->arg,
2454-
args->vararg->annotation, &annotations_len, loc) < 0)
2455-
return ERROR;
2456-
if (compiler_visit_argannotations(c, args->kwonlyargs, &annotations_len, loc) < 0)
2457-
return ERROR;
2458-
if (args->kwarg && args->kwarg->annotation &&
2459-
compiler_visit_argannotation(c, args->kwarg->arg,
2460-
args->kwarg->annotation, &annotations_len, loc) < 0)
2461-
return ERROR;
2447+
RETURN_IF_ERROR(
2448+
compiler_visit_argannotations(c, args->args, &annotations_len, loc));
24622449

2463-
if (compiler_visit_argannotation(c, &_Py_ID(return), returns,
2464-
&annotations_len, loc) < 0) {
2465-
return ERROR;
2450+
RETURN_IF_ERROR(
2451+
compiler_visit_argannotations(c, args->posonlyargs, &annotations_len, loc));
2452+
2453+
if (args->vararg && args->vararg->annotation) {
2454+
RETURN_IF_ERROR(
2455+
compiler_visit_argannotation(c, args->vararg->arg,
2456+
args->vararg->annotation, &annotations_len, loc));
2457+
}
2458+
2459+
RETURN_IF_ERROR(
2460+
compiler_visit_argannotations(c, args->kwonlyargs, &annotations_len, loc));
2461+
2462+
if (args->kwarg && args->kwarg->annotation) {
2463+
RETURN_IF_ERROR(
2464+
compiler_visit_argannotation(c, args->kwarg->arg,
2465+
args->kwarg->annotation, &annotations_len, loc));
24662466
}
24672467

2468+
RETURN_IF_ERROR(
2469+
compiler_visit_argannotation(c, &_Py_ID(return), returns, &annotations_len, loc));
2470+
24682471
if (annotations_len) {
24692472
ADDOP_I(c, loc, BUILD_TUPLE, annotations_len);
24702473
return 1;
@@ -2796,7 +2799,8 @@ compiler_class(struct compiler *c, stmt_ty s)
27962799
RETURN_IF_ERROR(compiler_apply_decorators(c, decos));
27972800

27982801
/* 7. store into <name> */
2799-
return compiler_nameop(c, loc, s->v.ClassDef.name, Store);
2802+
RETURN_IF_ERROR(compiler_nameop(c, loc, s->v.ClassDef.name, Store));
2803+
return SUCCESS;
28002804
}
28012805

28022806
/* Return false if the expression is a constant value except named singletons.
@@ -3865,9 +3869,7 @@ compiler_import(struct compiler *c, stmt_ty s)
38653869

38663870
if (alias->asname) {
38673871
r = compiler_import_as(c, loc, alias->name, alias->asname);
3868-
if (r == ERROR) {
3869-
return r;
3870-
}
3872+
RETURN_IF_ERROR(r);
38713873
}
38723874
else {
38733875
identifier tmp = alias->name;
@@ -4857,7 +4859,8 @@ validate_keywords(struct compiler *c, asdl_keyword_seq *keywords)
48574859
for (Py_ssize_t j = i + 1; j < nkeywords; j++) {
48584860
keyword_ty other = ((keyword_ty)asdl_seq_GET(keywords, j));
48594861
if (other->arg && !PyUnicode_Compare(key->arg, other->arg)) {
4860-
return compiler_error(c, LOC(other), "keyword argument repeated: %U", key->arg);
4862+
compiler_error(c, LOC(other), "keyword argument repeated: %U", key->arg);
4863+
return ERROR;
48614864
}
48624865
}
48634866
}
@@ -6498,7 +6501,8 @@ validate_kwd_attrs(struct compiler *c, asdl_identifier_seq *attrs, asdl_pattern_
64986501
identifier other = ((identifier)asdl_seq_GET(attrs, j));
64996502
if (!PyUnicode_Compare(attr, other)) {
65006503
location loc = LOC((pattern_ty) asdl_seq_GET(patterns, j));
6501-
return compiler_error(c, loc, "attribute name repeated in class pattern: %U", attr);
6504+
compiler_error(c, loc, "attribute name repeated in class pattern: %U", attr);
6505+
return ERROR;
65026506
}
65036507
}
65046508
}
@@ -6530,7 +6534,7 @@ compiler_pattern_class(struct compiler *c, pattern_ty p, pattern_context *pc)
65306534
}
65316535
VISIT(c, expr, p->v.MatchClass.cls);
65326536
PyObject *attr_names = PyTuple_New(nattrs);
6533-
if (!attr_names) {
6537+
if (attr_names == NULL) {
65346538
return ERROR;
65356539
}
65366540
Py_ssize_t i;
@@ -6647,7 +6651,9 @@ compiler_pattern_mapping(struct compiler *c, pattern_ty p,
66476651
compiler_error(c, LOC(p), e);
66486652
goto error;
66496653
}
6650-
RETURN_IF_ERROR(compiler_visit_expr(c, key));
6654+
if (compiler_visit_expr(c, key) < 0) {
6655+
goto error;
6656+
}
66516657
}
66526658

66536659
// all keys have been checked; there are no duplicates
@@ -6904,12 +6910,10 @@ compiler_pattern_sequence(struct compiler *c, pattern_ty p,
69046910
ADDOP(c, LOC(p), POP_TOP);
69056911
}
69066912
else if (star_wildcard) {
6907-
RETURN_IF_ERROR(
6908-
pattern_helper_sequence_subscr(c, LOC(p), patterns, star, pc));
6913+
RETURN_IF_ERROR(pattern_helper_sequence_subscr(c, LOC(p), patterns, star, pc));
69096914
}
69106915
else {
6911-
RETURN_IF_ERROR(
6912-
pattern_helper_sequence_unpack(c, LOC(p), patterns, star, pc));
6916+
RETURN_IF_ERROR(pattern_helper_sequence_unpack(c, LOC(p), patterns, star, pc));
69136917
}
69146918
return SUCCESS;
69156919
}
@@ -6982,7 +6986,7 @@ compiler_match_inner(struct compiler *c, stmt_ty s, pattern_context *pc)
69826986
ADDOP_I(c, LOC(m->pattern), COPY, 1);
69836987
}
69846988
pc->stores = PyList_New(0);
6985-
if (!pc->stores) {
6989+
if (pc->stores == NULL) {
69866990
return ERROR;
69876991
}
69886992
// Irrefutable cases must be either guarded, last, or both:
@@ -7009,9 +7013,7 @@ compiler_match_inner(struct compiler *c, stmt_ty s, pattern_context *pc)
70097013
// NOTE: Returning macros are safe again.
70107014
if (m->guard) {
70117015
RETURN_IF_ERROR(ensure_fail_pop(c, pc, 0));
7012-
RETURN_IF_ERROR(
7013-
compiler_jump_if(c, LOC(m->pattern), m->guard,
7014-
pc->fail_pop[0], 0));
7016+
RETURN_IF_ERROR(compiler_jump_if(c, LOC(m->pattern), m->guard, pc->fail_pop[0], 0));
70157017
}
70167018
// Success! Pop the subject off, we're done with it:
70177019
if (i != cases - has_default - 1) {
@@ -7037,8 +7039,7 @@ compiler_match_inner(struct compiler *c, stmt_ty s, pattern_context *pc)
70377039
ADDOP(c, LOC(m->pattern), NOP);
70387040
}
70397041
if (m->guard) {
7040-
RETURN_IF_ERROR(
7041-
compiler_jump_if(c, LOC(m->pattern), m->guard, end, 0));
7042+
RETURN_IF_ERROR(compiler_jump_if(c, LOC(m->pattern), m->guard, end, 0));
70427043
}
70437044
VISIT_SEQ(c, stmt, m->body);
70447045
}

0 commit comments

Comments
 (0)