Message347409
> 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. |
|
Date |
User |
Action |
Args |
2019-07-06 00:21:07 | tim.peters | set | recipients:
+ tim.peters, terry.reedy, nedbat, ned.deily, lukasz.langa, serhiy.storchaka, p-ganssle, pablogsal, miss-islington, xtreak, aldwinaldwin |
2019-07-06 00:21:07 | tim.peters | set | messageid: <1562372467.72.0.959257780574.issue37500@roundup.psfhosted.org> |
2019-07-06 00:21:07 | tim.peters | link | issue37500 messages |
2019-07-06 00:21:06 | tim.peters | create | |
|