forked from VimPlug/jedi
Do some parser tree caching. This might be important for recursions.
This commit is contained in:
@@ -45,6 +45,7 @@ def _memoize_default(default=_NO_DEFAULT, evaluator_is_first_arg=False, second_a
|
|||||||
memo[key] = rv
|
memo[key] = rv
|
||||||
return rv
|
return rv
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
6
jedi/evaluate/parser_cache.py
Normal file
6
jedi/evaluate/parser_cache.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from jedi.evaluate.cache import evaluator_function_cache
|
||||||
|
|
||||||
|
|
||||||
|
@evaluator_function_cache()
|
||||||
|
def get_yield_exprs(evaluator, funcdef):
|
||||||
|
return list(funcdef.iter_yield_exprs())
|
||||||
@@ -66,6 +66,7 @@ from jedi.evaluate.dynamic import search_params
|
|||||||
from jedi.evaluate import context
|
from jedi.evaluate import context
|
||||||
from jedi.evaluate.context import ContextualizedNode
|
from jedi.evaluate.context import ContextualizedNode
|
||||||
from jedi import parser_utils
|
from jedi import parser_utils
|
||||||
|
from jedi.evaluate.parser_cache import get_yield_exprs
|
||||||
|
|
||||||
|
|
||||||
def apply_py__get__(context, base_context):
|
def apply_py__get__(context, base_context):
|
||||||
@@ -258,7 +259,8 @@ class FunctionContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
|||||||
"""
|
"""
|
||||||
Created to be used by inheritance.
|
Created to be used by inheritance.
|
||||||
"""
|
"""
|
||||||
if self.tree_node.is_generator():
|
yield_exprs = get_yield_exprs(self.evaluator, self.tree_node)
|
||||||
|
if yield_exprs:
|
||||||
return set([iterable.Generator(self.evaluator, function_execution)])
|
return set([iterable.Generator(self.evaluator, function_execution)])
|
||||||
else:
|
else:
|
||||||
return function_execution.get_return_values()
|
return function_execution.get_return_values()
|
||||||
@@ -321,7 +323,7 @@ class FunctionExecutionContext(context.TreeContext):
|
|||||||
|
|
||||||
if check_yields:
|
if check_yields:
|
||||||
types = set()
|
types = set()
|
||||||
returns = funcdef.iter_yield_exprs()
|
returns = get_yield_exprs(self.evaluator, funcdef)
|
||||||
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))
|
||||||
@@ -364,7 +366,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.iter_yield_exprs()]
|
for y in get_yield_exprs(self.evaluator, self.tree_node)]
|
||||||
|
|
||||||
# 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 = []
|
||||||
|
|||||||
Reference in New Issue
Block a user