| Store | Cart

Re: [Python-Dev] Issue #26204: compiler now emits a SyntaxWarning on constant statement

From: MRAB <pyt...@mrabarnett.plus.com>
Mon, 8 Feb 2016 23:48:39 +0000
On 2016-02-08 23:21, Chris Barker wrote:
> On Mon, Feb 8, 2016 at 1:51 PM, Victor Stinner <vict...@gmail.com> <mailto:vict...@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 "<ipython-input-7-38940c80755c>", line 1>>      assert True,>>                  ^>> SyntaxError:invalid syntax>> I actually like the Warning with the note about the problem better:>>     <stdin>:1: SyntaxWarning: assertion is always true, perhaps remove>     parentheses?>>> And, of course, more relevant with something Falsey in the tuple:>> In [*14*]: assert (False,)>> <ipython-input-14-05f425f558c4>: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.
_______________________________________________
Python-Dev mailing list
Pyth...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/python-dev-ml%40activestate.com

Recent Messages in this Thread
Victor Stinner Feb 08, 2016 05:44 pm
francismb Feb 08, 2016 06:00 pm
xiscu Feb 08, 2016 06:11 pm
Ethan Furman Feb 08, 2016 06:12 pm
Gregory P. Smith Feb 08, 2016 06:06 pm
Ethan Furman Feb 08, 2016 06:15 pm
Ethan Furman Feb 08, 2016 08:39 pm
Guido van Rossum Feb 08, 2016 07:13 pm
Andrew Barnert via Python-Dev Feb 08, 2016 07:46 pm
Victor Stinner Feb 08, 2016 07:51 pm
Guido van Rossum Feb 08, 2016 08:34 pm
Victor Stinner Feb 08, 2016 09:20 pm
Guido van Rossum Feb 08, 2016 09:27 pm
John Mark Vandenberg Feb 08, 2016 09:37 pm
Alexander Walters Feb 08, 2016 09:41 pm
John Mark Vandenberg Feb 08, 2016 09:48 pm
John Mark Vandenberg Feb 09, 2016 02:38 am
Michel Desmoulin Feb 09, 2016 03:09 pm
Alexander Walters Feb 08, 2016 08:09 pm
Victor Stinner Feb 08, 2016 09:23 pm
Alexander Walters Feb 08, 2016 09:28 pm
Victor Stinner Feb 08, 2016 09:51 pm
John Mark Vandenberg Feb 08, 2016 10:14 pm
Terry Reedy Feb 08, 2016 10:19 pm
Yury Selivanov Feb 08, 2016 10:43 pm
Steven DAprano Feb 09, 2016 01:02 am
Yury Selivanov Feb 09, 2016 10:15 pm
Chris Barker Feb 08, 2016 11:21 pm
MRAB Feb 08, 2016 11:48 pm
Chris Barker Feb 09, 2016 12:08 am
Guido van Rossum Feb 09, 2016 12:53 am
MRAB Feb 09, 2016 01:41 am
Guido van Rossum Feb 09, 2016 01:49 am
Chris Angelico Feb 09, 2016 01:49 am
Guido van Rossum Feb 09, 2016 01:52 am
Joseph Martinot-Lagarde Feb 09, 2016 09:57 am
Victor Stinner Feb 09, 2016 10:06 am
Georg Brandl Feb 09, 2016 11:55 am
Messages in this thread