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

John Mark Vandenberg jayvdb at gmail.com
Mon Feb 8 21:38:40 EST 2016


On Tue, Feb 9, 2016 at 7:34 AM, Guido van Rossum <guido at python.org> wrote:
> On Mon, Feb 8, 2016 at 11:51 AM, Victor Stinner
> <victor.stinner at gmail.com> wrote:
>> Le 8 févr. 2016 8:14 PM, "Guido van Rossum" <guido at python.org> a écrit :
>>> Hum. I'm not excited by this idea. It is not bad syntax.
>>
>> Do you see an use case for "constant statements" other than strings and
>> ellipsis?
>
> The same use case as for all dead code: it could be a placeholder for
> something better in the future.

Allowing dead code is useful as it allows complex code to be left in
place.  It can be risky removing the code.

Unused literals are stupefyingly simple statements.
A line of merely a constant, e.g. 'True' or '1', does not present the
same risks or benefits.
That it is a hope for something better?
It could be easily replaced with 'pass', '...', a comment, and/or a
string literal explaining what needs improving.

> It could also be generated code where the generator expects the
> optimizer to remove it (or doesn't care).

Why shouldnt a user see that it is generating such code?
There is a decent chance that it is a bug in the generated code.

fwiw, this is a syntax warning in Ruby - "unused literal ignored",
since 2003 (5aadcd9).

--
John Vandenberg


More information about the Python-Dev mailing list