for / while else doesn't make sense

Chris Angelico rosuav at gmail.com
Sat May 21 06:08:21 EDT 2016


On Sat, May 21, 2016 at 7:56 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Sat, 21 May 2016 02:01 pm, Chris Angelico wrote:
>
>> On Sat, May 21, 2016 at 1:50 PM, Steven D'Aprano <steve at pearwood.info>
>> wrote:
>
>>> Would you classify the second line here:
>>>
>>> print("Hello World!")
>>> pass
>>>
>>>
>>> as a bug? What exactly would your bug report be? "pass statement does
>>> nothing, as expected. It should do nothing. Please fix."
>>>
>>
>> Yes, I would. It's not a bug in Python or CPython - it's a bug in the
>> second line of code there. It implies something that isn't the case.
>
> What do you think it implies?
>
> What part of the docs for "pass" implies this thing?
>
> help("pass"):
>
>     ``pass`` is a null operation --- when it is executed, nothing
>     happens. It is useful as a placeholder when a statement is
>     required syntactically, but no code needs to be executed, for
>     example:  [examples snipped]

So why is a statement required syntactically after that print call?
Surely that implies something about the programmer's intent? It
certainly isn't required according to the code you've shown me; and if
someone submitted this code to me, I'd query it ("was there something
else meant to be here?").

ChrisA



More information about the Python-list mailing list