Skip to content

Commit ef1001c

Browse files
committed
compiler_warn returns SUCCESS/ERROR
1 parent d5b624b commit ef1001c

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

Python/compile.c

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,8 +2841,7 @@ check_compare(struct compiler *c, expr_ty e)
28412841
const char *msg = (op == Is)
28422842
? "\"is\" with a literal. Did you mean \"==\"?"
28432843
: "\"is not\" with a literal. Did you mean \"!=\"?";
2844-
int ret = compiler_warn(c, LOC(e), msg);
2845-
return ret == 0 ? ERROR : SUCCESS;
2844+
return compiler_warn(c, LOC(e), msg);
28462845
}
28472846
}
28482847
left = right;
@@ -3968,11 +3967,9 @@ compiler_assert(struct compiler *c, stmt_ty s)
39683967
PyTuple_Check(s->v.Assert.test->v.Constant.value) &&
39693968
PyTuple_Size(s->v.Assert.test->v.Constant.value) > 0))
39703969
{
3971-
if (!compiler_warn(c, LOC(s), "assertion is always true, "
3972-
"perhaps remove parentheses?"))
3973-
{
3974-
return ERROR;
3975-
}
3970+
RETURN_IF_ERROR(
3971+
compiler_warn(c, LOC(s), "assertion is always true, "
3972+
"perhaps remove parentheses?"));
39763973
}
39773974
if (c->c_optimize) {
39783975
return SUCCESS;
@@ -4679,10 +4676,9 @@ check_caller(struct compiler *c, expr_ty e)
46794676
case JoinedStr_kind:
46804677
case FormattedValue_kind: {
46814678
location loc = LOC(e);
4682-
int ret = compiler_warn(c, loc, "'%.200s' object is not callable; "
4683-
"perhaps you missed a comma?",
4684-
infer_type(e)->tp_name);
4685-
return ret == 0 ? ERROR : SUCCESS;
4679+
return compiler_warn(c, loc, "'%.200s' object is not callable; "
4680+
"perhaps you missed a comma?",
4681+
infer_type(e)->tp_name);
46864682
}
46874683
default:
46884684
return SUCCESS;
@@ -4709,10 +4705,9 @@ check_subscripter(struct compiler *c, expr_ty e)
47094705
case GeneratorExp_kind:
47104706
case Lambda_kind: {
47114707
location loc = LOC(e);
4712-
int ret = compiler_warn(c, loc, "'%.200s' object is not subscriptable; "
4713-
"perhaps you missed a comma?",
4714-
infer_type(e)->tp_name);
4715-
return ret == 0 ? ERROR : SUCCESS;
4708+
return compiler_warn(c, loc, "'%.200s' object is not subscriptable; "
4709+
"perhaps you missed a comma?",
4710+
infer_type(e)->tp_name);
47164711
}
47174712
default:
47184713
return SUCCESS;
@@ -4744,12 +4739,11 @@ check_index(struct compiler *c, expr_ty e, expr_ty s)
47444739
case JoinedStr_kind:
47454740
case FormattedValue_kind: {
47464741
location loc = LOC(e);
4747-
int ret = compiler_warn(c, loc, "%.200s indices must be integers "
4748-
"or slices, not %.200s; "
4749-
"perhaps you missed a comma?",
4750-
infer_type(e)->tp_name,
4751-
index_type->tp_name);
4752-
return ret == 0 ? ERROR : SUCCESS;
4742+
return compiler_warn(c, loc, "%.200s indices must be integers "
4743+
"or slices, not %.200s; "
4744+
"perhaps you missed a comma?",
4745+
infer_type(e)->tp_name,
4746+
index_type->tp_name);
47534747
}
47544748
default:
47554749
return SUCCESS;
@@ -6155,7 +6149,7 @@ compiler_warn(struct compiler *c, location loc,
61556149
PyObject *msg = PyUnicode_FromFormatV(format, vargs);
61566150
va_end(vargs);
61576151
if (msg == NULL) {
6158-
return 0;
6152+
return ERROR;
61596153
}
61606154
if (PyErr_WarnExplicitObject(PyExc_SyntaxWarning, msg, c->c_filename,
61616155
loc.lineno, NULL, NULL) < 0)
@@ -6168,10 +6162,10 @@ compiler_warn(struct compiler *c, location loc,
61686162
compiler_error(c, loc, PyUnicode_AsUTF8(msg));
61696163
}
61706164
Py_DECREF(msg);
6171-
return 0;
6165+
return ERROR;
61726166
}
61736167
Py_DECREF(msg);
6174-
return 1;
6168+
return SUCCESS;
61756169
}
61766170

61776171
static int

0 commit comments

Comments
 (0)