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

Gregory P. Smith greg at krypto.org
Mon Feb 8 13:06:17 EST 2016


On Mon, Feb 8, 2016 at 9:44 AM Victor Stinner <victor.stinner at gmail.com>
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?
>

I'm +1 on this.

-gps


>
>
> 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/greg%40krypto.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20160208/427e18c1/attachment-0001.html>


More information about the Python-Dev mailing list