Commit dcf0a543 authored by Stefan Behnel's avatar Stefan Behnel

refactor "yield from" and "await" nodes a little to provide a cleaner split...

refactor "yield from" and "await" nodes a little to provide a cleaner split between them (await nodes are not yield-from nodes)
parent 0beafeee
...@@ -9491,20 +9491,9 @@ class YieldExprNode(ExprNode): ...@@ -9491,20 +9491,9 @@ class YieldExprNode(ExprNode):
code.put_incref(self.result(), py_object_type) code.put_incref(self.result(), py_object_type)
class YieldFromExprNode(YieldExprNode): class _YieldDelegationExprNode(YieldExprNode):
# "yield from GEN" expression
is_yield_from = True
expr_keyword = 'yield from'
def coerce_yield_argument(self, env):
if not self.arg.type.is_string:
# FIXME: support C arrays and C++ iterators?
error(self.pos, "yielding from non-Python object not supported")
self.arg = self.arg.coerce_to_pyobject(env)
def yield_from_func(self, code): def yield_from_func(self, code):
code.globalstate.use_utility_code(UtilityCode.load_cached("GeneratorYieldFrom", "Coroutine.c")) raise NotImplementedError()
return "__Pyx_Generator_Yield_From"
def generate_evaluation_code(self, code, source_cname=None, decref_source=False): def generate_evaluation_code(self, code, source_cname=None, decref_source=False):
if source_cname is None: if source_cname is None:
...@@ -9546,13 +9535,28 @@ class YieldFromExprNode(YieldExprNode): ...@@ -9546,13 +9535,28 @@ class YieldFromExprNode(YieldExprNode):
code.putln("}") code.putln("}")
class AwaitExprNode(YieldFromExprNode): class YieldFromExprNode(_YieldDelegationExprNode):
# "yield from GEN" expression
is_yield_from = True
expr_keyword = 'yield from'
def coerce_yield_argument(self, env):
if not self.arg.type.is_string:
# FIXME: support C arrays and C++ iterators?
error(self.pos, "yielding from non-Python object not supported")
self.arg = self.arg.coerce_to_pyobject(env)
def yield_from_func(self, code):
code.globalstate.use_utility_code(UtilityCode.load_cached("GeneratorYieldFrom", "Coroutine.c"))
return "__Pyx_Generator_Yield_From"
class AwaitExprNode(_YieldDelegationExprNode):
# 'await' expression node # 'await' expression node
# #
# arg ExprNode the Awaitable value to await # arg ExprNode the Awaitable value to await
# label_num integer yield label number # label_num integer yield label number
is_yield_from = False
is_await = True is_await = True
expr_keyword = 'await' expr_keyword = 'await'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment