mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
Move yields -> iter_yield_exprs.
This commit is contained in:
@@ -319,7 +319,7 @@ class FunctionExecutionContext(context.TreeContext):
|
|||||||
|
|
||||||
if check_yields:
|
if check_yields:
|
||||||
types = set()
|
types = set()
|
||||||
returns = funcdef.yields
|
returns = funcdef.iter_yield_exprs()
|
||||||
else:
|
else:
|
||||||
returns = funcdef.iter_return_stmts()
|
returns = funcdef.iter_return_stmts()
|
||||||
types = set(docstrings.infer_return_types(self.function_context))
|
types = set(docstrings.infer_return_types(self.function_context))
|
||||||
@@ -352,7 +352,7 @@ class FunctionExecutionContext(context.TreeContext):
|
|||||||
def get_yield_values(self):
|
def get_yield_values(self):
|
||||||
for_parents = [(y, tree.search_ancestor(y, ('for_stmt', 'funcdef',
|
for_parents = [(y, tree.search_ancestor(y, ('for_stmt', 'funcdef',
|
||||||
'while_stmt', 'if_stmt')))
|
'while_stmt', 'if_stmt')))
|
||||||
for y in self.tree_node.yields]
|
for y in self.tree_node.iter_yield_exprs()]
|
||||||
|
|
||||||
# Calculate if the yields are placed within the same for loop.
|
# Calculate if the yields are placed within the same for loop.
|
||||||
yields_order = []
|
yields_order = []
|
||||||
|
|||||||
@@ -239,9 +239,6 @@ class Scope(PythonBaseNode, DocstringMixin):
|
|||||||
def __init__(self, children):
|
def __init__(self, children):
|
||||||
super(Scope, self).__init__(children)
|
super(Scope, self).__init__(children)
|
||||||
|
|
||||||
def iter_return_stmts(self):
|
|
||||||
return self._search_in_scope(ReturnStmt)
|
|
||||||
|
|
||||||
def iter_funcdefs(self):
|
def iter_funcdefs(self):
|
||||||
return self._search_in_scope(Function)
|
return self._search_in_scope(Function)
|
||||||
|
|
||||||
@@ -461,13 +458,15 @@ class Function(ClassOrFunc):
|
|||||||
def name(self):
|
def name(self):
|
||||||
return self.children[1] # First token after `def`
|
return self.children[1] # First token after `def`
|
||||||
|
|
||||||
@property
|
def iter_yield_exprs(self):
|
||||||
def yields(self):
|
|
||||||
# TODO This is incorrect, yields are also possible in a statement.
|
# TODO This is incorrect, yields are also possible in a statement.
|
||||||
return list(self._search_in_scope(YieldExpr))
|
return self._search_in_scope(YieldExpr)
|
||||||
|
|
||||||
|
def iter_return_stmts(self):
|
||||||
|
return self._search_in_scope(ReturnStmt)
|
||||||
|
|
||||||
def is_generator(self):
|
def is_generator(self):
|
||||||
return bool(self.yields)
|
return next(self.iter_yield_exprs(), None) is not None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def annotation(self):
|
def annotation(self):
|
||||||
|
|||||||
@@ -52,12 +52,9 @@ class TestsFunctionAndLambdaParsing(object):
|
|||||||
assert node.is_generator() is expected.get('is_generator', False)
|
assert node.is_generator() is expected.get('is_generator', False)
|
||||||
|
|
||||||
def test_yields(self, node, expected):
|
def test_yields(self, node, expected):
|
||||||
# TODO: There's a comment in the code noting that the current implementation is incorrect. This returns an
|
# TODO: There's a comment in the code noting that the current
|
||||||
# empty list at the moment (not e.g. False).
|
# implementation is incorrect.
|
||||||
if expected.get('yields', False):
|
assert node.is_generator() == expected.get('yields', False)
|
||||||
assert node.yields
|
|
||||||
else:
|
|
||||||
assert not node.yields
|
|
||||||
|
|
||||||
def test_annotation(self, node, expected):
|
def test_annotation(self, node, expected):
|
||||||
expected_annotation = expected.get('annotation', None)
|
expected_annotation = expected.get('annotation', None)
|
||||||
|
|||||||
Reference in New Issue
Block a user