forked from VimPlug/jedi
get rid of the evaluate_generator param
This commit is contained in:
@@ -62,7 +62,10 @@ class Generator(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
|
|
||||||
def iter_content(self):
|
def iter_content(self):
|
||||||
""" returns the content of __iter__ """
|
""" returns the content of __iter__ """
|
||||||
return self.func.py__call__(self._evaluator, self.var_args, True)
|
# 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()
|
||||||
|
|
||||||
def get_index_types(self, index_array):
|
def get_index_types(self, index_array):
|
||||||
#debug.warning('Tried to get array access on a generator: %s', self)
|
#debug.warning('Tried to get array access on a generator: %s', self)
|
||||||
@@ -285,6 +288,7 @@ def get_iterator_types(inputs):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
debug.warning('Instance has no __next__ function in %s.', it)
|
debug.warning('Instance has no __next__ function in %s.', it)
|
||||||
else:
|
else:
|
||||||
|
# TODO this is not correct, __iter__ can return arbitrary input!
|
||||||
# Is a generator.
|
# Is a generator.
|
||||||
result += it.iter_content()
|
result += it.iter_content()
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ must stop recursions going mad. Some settings are here to make |jedi| stop at
|
|||||||
the right time. You can read more about them :ref:`here <settings-recursion>`.
|
the right time. You can read more about them :ref:`here <settings-recursion>`.
|
||||||
|
|
||||||
Next to :mod:`jedi.evaluate.cache` this module also makes |jedi| not
|
Next to :mod:`jedi.evaluate.cache` this module also makes |jedi| not
|
||||||
thread-safe. Why? ``ExecutionRecursionDecorator`` uses class variables to
|
thread-safe. Why? ``execution_recursion_decorator`` uses class variables to
|
||||||
count the function calls.
|
count the function calls.
|
||||||
"""
|
"""
|
||||||
from jedi.parser import representation as pr
|
from jedi.parser import representation as pr
|
||||||
@@ -100,12 +100,12 @@ class _RecursionNode(object):
|
|||||||
|
|
||||||
|
|
||||||
def execution_recursion_decorator(func):
|
def execution_recursion_decorator(func):
|
||||||
def run(execution, evaluate_generator=False):
|
def run(execution):
|
||||||
detector = execution._evaluator.execution_recursion_detector
|
detector = execution._evaluator.execution_recursion_detector
|
||||||
if detector.push_execution(execution, evaluate_generator):
|
if detector.push_execution(execution):
|
||||||
result = []
|
result = []
|
||||||
else:
|
else:
|
||||||
result = func(execution, evaluate_generator)
|
result = func(execution)
|
||||||
detector.pop_execution()
|
detector.pop_execution()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -123,13 +123,13 @@ class ExecutionRecursionDetector(object):
|
|||||||
self.execution_funcs = set()
|
self.execution_funcs = set()
|
||||||
self.execution_count = 0
|
self.execution_count = 0
|
||||||
|
|
||||||
def __call__(self, execution, evaluate_generator=False):
|
def __call__(self, execution):
|
||||||
debug.dbg('Execution recursions: %s', execution, self.recursion_level,
|
debug.dbg('Execution recursions: %s', execution, self.recursion_level,
|
||||||
self.execution_count, len(self.execution_funcs))
|
self.execution_count, len(self.execution_funcs))
|
||||||
if self.check_recursion(execution, evaluate_generator):
|
if self.check_recursion(execution):
|
||||||
result = []
|
result = []
|
||||||
else:
|
else:
|
||||||
result = self.func(execution, evaluate_generator)
|
result = self.func(execution)
|
||||||
self.pop_execution()
|
self.pop_execution()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ class ExecutionRecursionDetector(object):
|
|||||||
cls.parent_execution_funcs.pop()
|
cls.parent_execution_funcs.pop()
|
||||||
cls.recursion_level -= 1
|
cls.recursion_level -= 1
|
||||||
|
|
||||||
def push_execution(cls, execution, evaluate_generator):
|
def push_execution(cls, execution):
|
||||||
in_par_execution_funcs = execution.base in cls.parent_execution_funcs
|
in_par_execution_funcs = execution.base in cls.parent_execution_funcs
|
||||||
in_execution_funcs = execution.base in cls.execution_funcs
|
in_execution_funcs = execution.base in cls.execution_funcs
|
||||||
cls.recursion_level += 1
|
cls.recursion_level += 1
|
||||||
@@ -151,7 +151,7 @@ class ExecutionRecursionDetector(object):
|
|||||||
if isinstance(execution.base, (iterable.Array, iterable.Generator)):
|
if isinstance(execution.base, (iterable.Array, iterable.Generator)):
|
||||||
return False
|
return False
|
||||||
module = execution.get_parent_until()
|
module = execution.get_parent_until()
|
||||||
if evaluate_generator or module == compiled.builtin:
|
if module == compiled.builtin:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if in_par_execution_funcs:
|
if in_par_execution_funcs:
|
||||||
|
|||||||
@@ -250,12 +250,13 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
def isinstance(self, *cls):
|
def isinstance(self, *cls):
|
||||||
return isinstance(self.var, cls)
|
return isinstance(self.var, cls)
|
||||||
|
|
||||||
def py__call__(self, evaluator, params, evaluate_generator=False):
|
def py__call__(self, evaluator, params):
|
||||||
# TODO this should be working nicer.
|
# TODO this should be working nicer.
|
||||||
if isinstance(self.var, (compiled.CompiledObject, Instance)):
|
if isinstance(self.var, (compiled.CompiledObject, Instance)):
|
||||||
return self.var.py__call__(evaluator, params)
|
return self.var.py__call__(evaluator, params)
|
||||||
stmts = FunctionExecution(evaluator, self, params) \
|
if self.is_generator:
|
||||||
.get_return_types(evaluate_generator)
|
return [iterable.Generator(evaluator, self, params)]
|
||||||
|
stmts = FunctionExecution(evaluator, self, params).get_return_types()
|
||||||
return stmts
|
return stmts
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@@ -421,10 +422,11 @@ class Function(use_metaclass(CachedMetaClass, pr.IsScope)):
|
|||||||
def get_magic_function_scope(self):
|
def get_magic_function_scope(self):
|
||||||
return compiled.magic_function_class
|
return compiled.magic_function_class
|
||||||
|
|
||||||
def py__call__(self, evaluator, params, evaluate_generator=False):
|
def py__call__(self, evaluator, params):
|
||||||
stmts = FunctionExecution(evaluator, self, params) \
|
if self.is_generator:
|
||||||
.get_return_types(evaluate_generator)
|
return [iterable.Generator(evaluator, self, params)]
|
||||||
return stmts
|
else:
|
||||||
|
return FunctionExecution(evaluator, self, params).get_return_types()
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
return getattr(self.base_func, name)
|
return getattr(self.base_func, name)
|
||||||
@@ -448,7 +450,7 @@ class FunctionExecution(Executed):
|
|||||||
"""
|
"""
|
||||||
@memoize_default(default=())
|
@memoize_default(default=())
|
||||||
@recursion.execution_recursion_decorator
|
@recursion.execution_recursion_decorator
|
||||||
def get_return_types(self, evaluate_generator=False):
|
def get_return_types(self):
|
||||||
func = self.base
|
func = self.base
|
||||||
# Feed the listeners, with the params.
|
# Feed the listeners, with the params.
|
||||||
for listener in func.listeners:
|
for listener in func.listeners:
|
||||||
@@ -459,9 +461,6 @@ 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 []
|
||||||
|
|
||||||
if func.is_generator and not evaluate_generator:
|
|
||||||
return [iterable.Generator(self._evaluator, func, self.var_args)]
|
|
||||||
else:
|
|
||||||
stmts = list(docstrings.find_return_types(self._evaluator, func))
|
stmts = list(docstrings.find_return_types(self._evaluator, func))
|
||||||
for r in self.returns:
|
for r in self.returns:
|
||||||
if r is not None:
|
if r is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user