[Python-Dev] Issue #26204: compiler now emits a SyntaxWarning on constant statement (original) (raw)

MRAB python at mrabarnett.plus.com
Mon Feb 8 18:48:39 EST 2016


On 2016-02-08 23:21, Chris Barker wrote:

On Mon, Feb 8, 2016 at 1:51 PM, Victor Stinner <victor.stinner at gmail.com_ _<mailto:victor.stinner at gmail.com>> wrote:

I didn't know. I just checked. It's assert used with a non-empty tuple: >>> assert ("tuple",)

which is more interesting with a tuple without the parentheses: t = In [4]: t = True, In [5]: t Out[5]: (True,) works fine, but not if you use an assert: In [7]: assert True, File "", line 1 assert True, ^ SyntaxError:invalid syntax I actually like the Warning with the note about the problem better: :1: SyntaxWarning: assertion is always true, perhaps remove parentheses? And, of course, more relevant with something Falsey in the tuple: In [14]: assert (False,) :1: SyntaxWarning: assertion is always true, perhaps remove parentheses? assert (False,) But I am curious why you get a different error without the parens? Try:

 help('assert')

You'll see that in "assert (True,)", the tuple (an object) is the first condition (and probably a mistake), whereas in "assert True,", the True is the condition and the second expression (after the comma) is missing.



More information about the Python-Dev mailing list