1
0
forked from VimPlug/jedi

Fix generators.

This commit is contained in:
Dave Halter
2014-11-14 02:05:25 +01:00
parent 13a128b160
commit 278bc9d705
4 changed files with 19 additions and 6 deletions

View File

@@ -164,6 +164,7 @@ class Evaluator(object):
debug.dbg('eval_statement result %s', types) debug.dbg('eval_statement result %s', types)
return types return types
@memoize_default(evaluator_is_first_arg=True)
def eval_element(self, element): def eval_element(self, element):
debug.dbg('eval_element %s', element) debug.dbg('eval_element %s', element)
if isinstance(element, (pr.Name, pr.Literal)) or pr.is_node(element, 'atom'): if isinstance(element, (pr.Name, pr.Literal)) or pr.is_node(element, 'atom'):

View File

@@ -84,7 +84,8 @@ class Generator(use_metaclass(CachedMetaClass, IterableWrapper, GeneratorMixin))
# Directly execute it, because with a normal call to py__call__ a # Directly execute it, because with a normal call to py__call__ a
# Generator will be returned. # Generator will be returned.
from jedi.evaluate.representation import FunctionExecution 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): def __getattr__(self, name):
if name not in ['start_pos', 'end_pos', 'parent', 'get_imports', if name not in ['start_pos', 'end_pos', 'parent', 'get_imports',

View File

@@ -100,12 +100,12 @@ class _RecursionNode(object):
def execution_recursion_decorator(func): def execution_recursion_decorator(func):
def run(execution): def run(execution, **kwargs):
detector = execution._evaluator.execution_recursion_detector detector = execution._evaluator.execution_recursion_detector
if detector.push_execution(execution): if detector.push_execution(execution):
result = [] result = []
else: else:
result = func(execution) result = func(execution, **kwargs)
detector.pop_execution() detector.pop_execution()
return result return result

View File

@@ -567,7 +567,7 @@ class FunctionExecution(Executed):
@memoize_default(default=()) @memoize_default(default=())
@recursion.execution_recursion_decorator @recursion.execution_recursion_decorator
def get_return_types(self): def get_return_types(self, check_yields=False):
func = self.base func = self.base
if func.listeners: if func.listeners:
@@ -579,8 +579,14 @@ class FunctionExecution(Executed):
# inserted params, not in the actual execution of the function. # inserted params, not in the actual execution of the function.
return [] return []
types = list(docstrings.find_return_types(self._evaluator, func)) if check_yields:
for r in self.returns: 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) check = flow_analysis.break_check(self._evaluator, self, r)
if check is flow_analysis.UNREACHABLE: if check is flow_analysis.UNREACHABLE:
debug.dbg('Return unreachable: %s', r) debug.dbg('Return unreachable: %s', r)
@@ -661,6 +667,11 @@ class FunctionExecution(Executed):
def returns(self): def returns(self):
return self._copy_list(self.base.returns) 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 @common.safe_property
@memoize_default([]) @memoize_default([])
def children(self): def children(self):