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

Ethan Furman ethan at stoneleaf.us
Mon Feb 8 13:12:57 EST 2016


On 02/08/2016 10:00 AM, francismb wrote:
 > On 02/08/2016 06:44 PM, Victor Stinner wrote:

 >> 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.
 >>
 > [...]
 >> 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
 >
 > Just for my understanding:
 >
 > What would happen if someone has functions where some return
 > constant expressions and others not and then that functions
 > are used depending on some other context. E.g:
 >
 > def behaviour2(ctx):
 >     return 1
 >
 > def behaviour1(ctx):
 >     return some_calculation_with(ctx)
 >
 >
 > [...]
 >
 > if ... :
 >    return behaviour1(ctx)
 > else :
 >    return behaviour2()
 >
 >
 > Is that going to raise a warning?

No, because those constants are being used (returned).  Only constants 
that aren't used at all get omitted.

--
~Ethan~


More information about the Python-Dev mailing list