Author: Raffael Tfirst <raffael.tfi...@gmail.com> Branch: py3.5-async Changeset: r85866:088b0533e388 Date: 2016-07-25 21:45 +0200 http://bitbucket.org/pypy/pypy/changeset/088b0533e388/
Log: Only check flags if iterable object is a coroutine, split getawaitable for generator and coroutine diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py --- a/pypy/interpreter/generator.py +++ b/pypy/interpreter/generator.py @@ -302,6 +302,10 @@ self.descr_close() break block = block.previous + + def _GetAwaitableIter(self, o): + #look at typeobject.c, change to self.space.lookup(w_manager, "__await__") + return o class Coroutine(W_Root): @@ -568,10 +572,7 @@ block = block.previous def _GetAwaitableIter(self, o): - import pdb; pdb.set_trace() - if isinstance(o, Coroutine): - return o - getter = None + return o diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py --- a/pypy/interpreter/pyopcode.py +++ b/pypy/interpreter/pyopcode.py @@ -1031,15 +1031,17 @@ def YIELD_FROM(self, oparg, next_instr): from pypy.interpreter.astcompiler import consts + from pypy.interpreter.generator import Coroutine space = self.space w_value = self.popvalue() w_gen = self.peekvalue() - if (w_gen.descr_gi_code(w_gen).co_flags & consts.CO_COROUTINE and - not self.pycode.co_flags & (consts.CO_COROUTINE | - consts.CO_ITERABLE_COROUTINE)): - raise oefmt(self.space.w_TypeError, - "cannot 'yield from' a coroutine object " - "from a generator") + if isinstance(w_gen, Coroutine): + if (w_gen.descr_gi_code(w_gen).co_flags & consts.CO_COROUTINE and + not self.pycode.co_flags & (consts.CO_COROUTINE | + consts.CO_ITERABLE_COROUTINE)): + raise oefmt(self.space.w_TypeError, + "cannot 'yield from' a coroutine object " + "from a generator") try: if space.is_none(w_value): w_retval = space.next(w_gen) @@ -1424,13 +1426,15 @@ def GET_YIELD_FROM_ITER(self, oparg, next_instr): from pypy.interpreter.astcompiler import consts + from pypy.interpreter.generator import Coroutine w_iterable = self.popvalue() + if isinstance(w_iterable, Coroutine): + if not self.pycode.co_flags & (consts.CO_COROUTINE | + consts.CO_ITERABLE_COROUTINE): + raise oefmt(self.space.w_TypeError, + "cannot 'yield from' a coroutine object " + "in a non-coroutine generator") w_iterator = self.space.iter(w_iterable) - if not self.pycode.co_flags & (consts.CO_COROUTINE | - consts.CO_ITERABLE_COROUTINE): - raise oefmt(self.space.w_TypeError, - "cannot 'yield from' a coroutine object " - "in a non-coroutine generator") self.pushvalue(w_iterator) def GET_AWAITABLE(self, oparg, next_instr): @@ -1459,7 +1463,6 @@ def GET_AITER(self, oparg, next_instr): w_iterable = self.popvalue() - import pdb; pdb.set_trace() self.pushvalue(w_iterable) def GET_ANEXT(self, oparg, next_instr): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit