summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2008-03-15 22:03:18 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2008-03-15 22:03:18 (GMT)
commit400aedacc06ac33c2bb488f3f95a90f11e96e168 (patch)
tree9a33f529ab9565563edad0cbca5da652e0a1f6c5 /Python
parentcd6bfab4101f8923aadfdf392b9d0615a9686064 (diff)
downloadcpython-400aedacc06ac33c2bb488f3f95a90f11e96e168.zip
cpython-400aedacc06ac33c2bb488f3f95a90f11e96e168.tar.gz
cpython-400aedacc06ac33c2bb488f3f95a90f11e96e168.tar.bz2
Add a warning for code like:
assert (0, 'message') An empty tuple does not create a warning. While questionable usage: assert (), 'message' should not display a warning. Tested manually. The warning message could be improved. Feel free to update it.
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 43b7569..47a63e7 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -2056,6 +2056,14 @@ compiler_assert(struct compiler *c, stmt_ty s)
if (assertion_error == NULL)
return 0;
}
+ if (s->v.Assert.test->kind == Tuple_kind &&
+ asdl_seq_LEN(s->v.Assert.test->v.Tuple.elts) > 0) {
+ const char* msg =
+ "assertion is always true, perhaps remove parentheses?";
+ if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, c->c_filename,
+ c->u->u_lineno, NULL, NULL) == -1)
+ return 0;
+ }
VISIT(c, expr, s->v.Assert.test);
end = compiler_new_block(c);
if (end == NULL)