summaryrefslogtreecommitdiff
path: root/Python/compile.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/Python/compile.c b/Python/compile.c
index ccb05cf1ac..84b79a2fff 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -2616,20 +2616,39 @@ compiler_visit_stmt_expr(struct compiler *c, expr_ty value)
return 1;
}
- if (value->kind == Str_kind || value->kind == Num_kind) {
- /* ignore strings and numbers */
+ switch (value->kind)
+ {
+ case Str_kind:
+ case Ellipsis_kind:
+ /* Issue #26204: ignore string statement, but don't emit a
+ * SyntaxWarning. Triple quoted strings is a common syntax for
+ * multiline comments.
+ *
+ * Don't emit warning on "def f(): ..." neither. It's a legit syntax
+ * for abstract function. */
return 1;
- }
- if (value->kind == Constant_kind) {
- PyObject *cst = value->v.Constant.value;
- if (PyUnicode_CheckExact(cst)
- || PyLong_CheckExact(cst)
- || PyFloat_CheckExact(cst)
- || PyComplex_CheckExact(cst)) {
- /* ignore strings and numbers */
- return 1;
+ case Bytes_kind:
+ case Num_kind:
+ case NameConstant_kind:
+ case Constant_kind:
+ {
+ PyObject *msg = PyUnicode_FromString("ignore constant statement");
+ if (msg == NULL)
+ return 0;
+ if (PyErr_WarnExplicitObject(PyExc_SyntaxWarning,
+ msg,
+ c->c_filename, c->u->u_lineno,
+ NULL, NULL) == -1) {
+ Py_DECREF(msg);
+ return 0;
}
+ Py_DECREF(msg);
+ return 1;
+ }
+
+ default:
+ break;
}
VISIT(c, expr, value);