[Python-ideas] x=(yield from) confusion [was:Yet another alternative name for yield-from]
Jim Jewett
jimjjewett at gmail.com
Fri Apr 10 04:41:59 CEST 2009
On 4/9/09, Jacob Holm <jh at improva.dk> wrote:
> Jim Jewett wrote:
>> On 4/9/09, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>> Jacob Holm wrote:
>>>> ... when close() catches a
>>>> StopIteration with a non-None value, it should either return it or raise
>> This implies that the value is always important; ...
> If you return None (or no value) you won't get an exception
Think of all the C functions that return a success status, or the
number of bytes read/written. Checking the return code is good, but
not checking it isn't always worth an Exception.
>> ... does suggest that yield-from *should* accept pre-started
>> generators, if only because the previous line (or a decorator) may
>> have primed it.
> That was my argument, but since there is no sane way of handling
> pre-primed generators without extending the PEP in a direction that
> Guido has forbidden,
Huh? All you need to do is to not care whether the generator is fresh
or not (let alone primed vs half-used).
If it won't be primed, *and* you can't afford to send back an extra
junk yield, then you need to prime it yourself. That can be awkward,
but so are all the syntax extensions that boil down to "and implicitly
call next for me once". (And the "oops, just this once, don't prime
it after all" extensions are even worse.)
-jJ
More information about the Python-ideas
mailing list