Yield expressions are now separate form ReturnStmt.

This commit is contained in:
Dave Halter
2014-10-29 18:54:05 +01:00
parent 71c3d34965
commit f09ff04fcc
3 changed files with 15 additions and 5 deletions

View File

@@ -512,7 +512,7 @@ class Function(use_metaclass(CachedMetaClass, Wrapper)):
@Python3Method @Python3Method
def py__call__(self, evaluator, params): def py__call__(self, evaluator, params):
if self.is_generator: if self.base.is_generator():
return [iterable.Generator(evaluator, self, params)] return [iterable.Generator(evaluator, self, params)]
else: else:
return FunctionExecution(evaluator, self, params).get_return_types() return FunctionExecution(evaluator, self, params).get_return_types()

View File

@@ -78,7 +78,7 @@ def convert(grammar, raw_node):
'continue_stmt': pr.KeywordStatement, 'continue_stmt': pr.KeywordStatement,
'return_stmt': pr.ReturnStmt, 'return_stmt': pr.ReturnStmt,
'raise_stmt': pr.KeywordStatement, 'raise_stmt': pr.KeywordStatement,
'yield_stmt': pr.ReturnStmt, 'yield_expr': pr.YieldExpr,
'del_stmt': pr.KeywordStatement, 'del_stmt': pr.KeywordStatement,
'pass_stmt': pr.KeywordStatement, 'pass_stmt': pr.KeywordStatement,
'global_stmt': pr.GlobalStmt, 'global_stmt': pr.GlobalStmt,

View File

@@ -441,15 +441,13 @@ class Scope(Simple, DocstringMixin):
:param start_pos: The position (line and column) of the scope. :param start_pos: The position (line and column) of the scope.
:type start_pos: tuple(int, int) :type start_pos: tuple(int, int)
""" """
__slots__ = ('imports', '_doc_token', 'asserts', 'names_dict', __slots__ = ('imports', '_doc_token', 'asserts', 'names_dict')
'is_generator')
def __init__(self, children): def __init__(self, children):
super(Scope, self).__init__(children) super(Scope, self).__init__(children)
self.imports = [] self.imports = []
self._doc_token = None self._doc_token = None
self.asserts = [] self.asserts = []
self.is_generator = False
@property @property
def returns(self): def returns(self):
@@ -784,6 +782,14 @@ class Function(ClassOrFunc):
else: else:
return [Param(node[0], self)] return [Param(node[0], self)]
@property
def yields(self):
# TODO This is incorrect, yields are also possible in a statement.
return self._search_in_scope(YieldExpr)
def is_generator(self):
return bool(self.yields)
def annotation(self): def annotation(self):
try: try:
return self.children[6] # 6th element: def foo(...) -> bar return self.children[6] # 6th element: def foo(...) -> bar
@@ -1074,6 +1080,10 @@ class ReturnStmt(Simple):
pass pass
class YieldExpr(Simple):
pass
class Statement(Simple, DocstringMixin): class Statement(Simple, DocstringMixin):
""" """
This is the class for all the possible statements. Which means, this class This is the class for all the possible statements. Which means, this class