[Python-Dev] Issue #26204: compiler now emits a SyntaxWarning on constant statement
Alexander Walters
tritium-list at sdamon.com
Mon Feb 8 15:09:22 EST 2016
I am not keen on a SyntaxWarning. Either something is python syntax, or
it is not. This warning catches something linters have been catching
for ages. I really don't see the value in adding this, and can see it
causing more confusion than it solves. In the #python irc channel, we
see quite a few newbie mistakes, but declaring a constant that isn't
used is rarely if ever one of them.
On 2/8/2016 12:44, Victor Stinner wrote:
> Hi,
>
> I changed the Python compiler to ignore any kind "constant
> expressions", whereas it only ignored strings and integers before:
> http://bugs.python.org/issue26204
>
> The compiler now also emits a SyntaxWarning on such case. IMHO the
> warning can help to detect bugs for developers who just learnt Python.
>
> The warning is *not* emited for strings, since triple quoted strings
> are a common syntax for multiline comments.
>
> The warning is *not* emited neither for ellispis (...) since "f():
> ..." is a legit syntax for abstract function.
>
> Are you ok with the new warning?
>
>
> New behaviour:
>
> haypo at smithers$ ./python
> Python 3.6.0a0 (default:759a975e1230, Feb 8 2016, 18:21:23)
>>>> def f():
> ... False
> ...
> <stdin>:2: SyntaxWarning: ignore constant statement
>
>>>> import dis; dis.dis(f)
> 2 0 LOAD_CONST 0 (None)
> 3 RETURN_VALUE
>
>
> Old behaviour:
>
> haypo at smithers$ python3
> Python 3.4.3 (default, Jun 29 2015, 12:16:01)
>>>> def f():
> ... False
> ...
>>>> import dis; dis.dis(f)
> 2 0 LOAD_CONST 1 (False)
> 3 POP_TOP
> 4 LOAD_CONST 0 (None)
> 7 RETURN_VALUE
>
>
>
> Before strings and numbers were already ignored. Example:
>
> haypo at smithers$ python3
> Python 3.4.3 (default, Jun 29 2015, 12:16:01)
>
>>>> def f():
> ... 123
> ...
>>>> import dis; dis.dis(f)
> 2 0 LOAD_CONST 0 (None)
> 3 RETURN_VALUE
>
>
> Victor
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/tritium-list%40sdamon.com
More information about the Python-Dev
mailing list