diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2008-03-15 22:03:18 +0000 |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2008-03-15 22:03:18 +0000 |
commit | 4511ca3d0a3f8412aeb65a6f7f5d0c351b0191a2 (patch) | |
tree | 799984474f6e8d0c79fc1c77fd9fd85378784c56 /Python/compile.c | |
parent | b0ec7f66af47fe72d3bba0d3f5f26ed3f65e0603 (diff) | |
download | cpython-4511ca3d0a3f8412aeb65a6f7f5d0c351b0191a2.tar.gz |
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/compile.c')
-rw-r--r-- | Python/compile.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c index 43b7569e62..47a63e7315 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) |