[Python-ideas] Revised**12 PEP on Yield-From
Scott David Daniels
Scott.Daniels at Acm.Org
Sun Apr 19 17:52:21 CEST 2009
Jacob Holm wrote:
> ...
> _i = iter(EXPR)
> _m, _a = next, (_i,)
> while 1:
> try:
> _y = _m(*_a)
> except StopIteration as _e:
> _r = _e.value
> break
> try:
> _s = yield _y
> except GeneratorExit as _e:
> try:
> _m = _i.close
> except AttributeError:
> pass
> else:
> _m()
> raise _e
> except BaseException as _e:
> _a = sys.exc_info()
> try:
> _m = _i.throw
> except AttributeError:
> raise _e
> else:
> if _s is None:
> _m, _a = next, (_i,)
> else:
> _m, _a = _i.send, (_s,)
> RESULT = _r
>
Now that we passed the magic three or four threshold, is
it not easier to read if we pick some better names?
_iter = iter(EXPR)
_call, _arg = next, _iter
while 1:
try:
_out = _call(_arg)
except StopIteration as _except:
_result = _except.value
break
try:
_in = yield _out
except GeneratorExit as _except:
try:
_close = _iter.close
except AttributeError:
pass
else:
_close()
raise _except
except BaseException as _except:
_a = sys.exc_info()
try:
_call = _iter.throw
except AttributeError:
raise _except
else:
if _in is None:
_call, _arg = next, _iter
else:
_call, _arg = _iter.send, _in
RESULT = _result
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-ideas
mailing list