Author tim.peters
Recipients aldwinaldwin, lukasz.langa, miss-islington, ned.deily, nedbat, p-ganssle, pablogsal, serhiy.storchaka, terry.reedy, tim.peters, xtreak
Date 2019-07-06.00:21:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1562372467.72.0.959257780574.issue37500@roundup.psfhosted.org>
In-reply-to
Content
> we could say that it does not matter if
>
> def f():
>   if 0:
>     yield
>
> should be or not a generator

Slippery slope arguments play better if they're made _before_ a decade has passed after the slope was fully greased.

There's nothing accidental about how `yield` behaves here.  I wrote the original generator PEP, and very deliberately added these to its doctests (in test_generators.py):

"""
>>> def f():
...    if 0:
...        yield
>>> type(f())
<class 'generator'>


>>> def f():
...     if 0:
...         yield 1
>>> type(f())
<class 'generator'>

>>> def f():
...    if "":
...        yield None
>>> type(f())
<class 'generator'>
"""

Any alternate implementation that decided that whether "it's a generator" depended on optimizations would likely fail at least one of those tests.  It was intended to be solely a compile-time decision, based purely on syntactic analysis.

So I've seen no reason to believe - or expect - that the damage here goes - or will ever go - deeper than that some dead code isn't raising compile-time errors in some rare cases (statements allowed only at function level being used in dead code outside function level).

Which should be fixed, if possible.  But, as damage goes - sorry! - it just seems minimal to me.
History
Date User Action Args
2019-07-06 00:21:07tim.peterssetrecipients: + tim.peters, terry.reedy, nedbat, ned.deily, lukasz.langa, serhiy.storchaka, p-ganssle, pablogsal, miss-islington, xtreak, aldwinaldwin
2019-07-06 00:21:07tim.peterssetmessageid: <1562372467.72.0.959257780574.issue37500@roundup.psfhosted.org>
2019-07-06 00:21:07tim.peterslinkissue37500 messages
2019-07-06 00:21:06tim.peterscreate