forked from VimPlug/jedi
Fix generators.
This commit is contained in:
@@ -164,6 +164,7 @@ class Evaluator(object):
|
||||
debug.dbg('eval_statement result %s', types)
|
||||
return types
|
||||
|
||||
@memoize_default(evaluator_is_first_arg=True)
|
||||
def eval_element(self, element):
|
||||
debug.dbg('eval_element %s', element)
|
||||
if isinstance(element, (pr.Name, pr.Literal)) or pr.is_node(element, 'atom'):
|
||||
|
||||
@@ -84,7 +84,8 @@ class Generator(use_metaclass(CachedMetaClass, IterableWrapper, GeneratorMixin))
|
||||
# Directly execute it, because with a normal call to py__call__ a
|
||||
# Generator will be returned.
|
||||
from jedi.evaluate.representation import FunctionExecution
|
||||
return FunctionExecution(self._evaluator, self.func, self.var_args).get_return_types()
|
||||
f = FunctionExecution(self._evaluator, self.func, self.var_args)
|
||||
return f.get_return_types(check_yields=True)
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name not in ['start_pos', 'end_pos', 'parent', 'get_imports',
|
||||
|
||||
@@ -100,12 +100,12 @@ class _RecursionNode(object):
|
||||
|
||||
|
||||
def execution_recursion_decorator(func):
|
||||
def run(execution):
|
||||
def run(execution, **kwargs):
|
||||
detector = execution._evaluator.execution_recursion_detector
|
||||
if detector.push_execution(execution):
|
||||
result = []
|
||||
else:
|
||||
result = func(execution)
|
||||
result = func(execution, **kwargs)
|
||||
detector.pop_execution()
|
||||
return result
|
||||
|
||||
|
||||
@@ -567,7 +567,7 @@ class FunctionExecution(Executed):
|
||||
|
||||
@memoize_default(default=())
|
||||
@recursion.execution_recursion_decorator
|
||||
def get_return_types(self):
|
||||
def get_return_types(self, check_yields=False):
|
||||
func = self.base
|
||||
|
||||
if func.listeners:
|
||||
@@ -579,8 +579,14 @@ class FunctionExecution(Executed):
|
||||
# inserted params, not in the actual execution of the function.
|
||||
return []
|
||||
|
||||
types = list(docstrings.find_return_types(self._evaluator, func))
|
||||
for r in self.returns:
|
||||
if check_yields:
|
||||
types = []
|
||||
returns = self.yields
|
||||
else:
|
||||
returns = self.returns
|
||||
types = list(docstrings.find_return_types(self._evaluator, func))
|
||||
|
||||
for r in returns:
|
||||
check = flow_analysis.break_check(self._evaluator, self, r)
|
||||
if check is flow_analysis.UNREACHABLE:
|
||||
debug.dbg('Return unreachable: %s', r)
|
||||
@@ -661,6 +667,11 @@ class FunctionExecution(Executed):
|
||||
def returns(self):
|
||||
return self._copy_list(self.base.returns)
|
||||
|
||||
@common.safe_property
|
||||
@memoize_default([])
|
||||
def yields(self):
|
||||
return self._copy_list(self.base.yields)
|
||||
|
||||
@common.safe_property
|
||||
@memoize_default([])
|
||||
def children(self):
|
||||
|
||||
Reference in New Issue
Block a user