forked from VimPlug/jedi
search_ancestor now uses *node_types as a parameter instead of a mix of tuple and simple string like isinstance.
This commit is contained in:
@@ -337,7 +337,7 @@ class Evaluator(object):
|
|||||||
# This is the first global lookup.
|
# This is the first global lookup.
|
||||||
stmt = atom.get_definition()
|
stmt = atom.get_definition()
|
||||||
if stmt.type == 'comp_for':
|
if stmt.type == 'comp_for':
|
||||||
stmt = tree.search_ancestor(stmt, ('expr_stmt', 'lambdef', 'funcdef', 'classdef'))
|
stmt = tree.search_ancestor(stmt, 'expr_stmt', 'lambdef', 'funcdef', 'classdef')
|
||||||
if stmt is None or stmt.type != 'expr_stmt':
|
if stmt is None or stmt.type != 'expr_stmt':
|
||||||
# We only need to adjust the start_pos for statements, because
|
# We only need to adjust the start_pos for statements, because
|
||||||
# there the name cannot be used.
|
# there the name cannot be used.
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ from jedi.evaluate.filters import AbstractNameDefinition
|
|||||||
@memoize_default(default=set())
|
@memoize_default(default=set())
|
||||||
def infer_import(context, tree_name, is_goto=False):
|
def infer_import(context, tree_name, is_goto=False):
|
||||||
module_context = context.get_root_context()
|
module_context = context.get_root_context()
|
||||||
import_node = search_ancestor(tree_name, ('import_name', 'import_from'))
|
import_node = search_ancestor(tree_name, 'import_name', 'import_from')
|
||||||
import_path = import_node.get_path_for_name(tree_name)
|
import_path = import_node.get_path_for_name(tree_name)
|
||||||
from_import_name = None
|
from_import_name = None
|
||||||
evaluator = context.evaluator
|
evaluator = context.evaluator
|
||||||
|
|||||||
@@ -350,8 +350,8 @@ class FunctionExecutionContext(context.TreeContext):
|
|||||||
|
|
||||||
@recursion.execution_recursion_decorator(default=iter([]))
|
@recursion.execution_recursion_decorator(default=iter([]))
|
||||||
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 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.
|
||||||
|
|||||||
@@ -1013,7 +1013,7 @@ class Param(PythonBaseNode):
|
|||||||
"""
|
"""
|
||||||
Returns the function/lambda of a parameter.
|
Returns the function/lambda of a parameter.
|
||||||
"""
|
"""
|
||||||
return search_ancestor(self, ('funcdef', 'lambdef'))
|
return search_ancestor(self, 'funcdef', 'lambdef')
|
||||||
|
|
||||||
def get_code(self, normalized=False, include_prefix=True, include_comma=True):
|
def get_code(self, normalized=False, include_prefix=True, include_comma=True):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -2,21 +2,18 @@ from abc import abstractmethod, abstractproperty
|
|||||||
from jedi._compatibility import utf8_repr, encoding, is_py3
|
from jedi._compatibility import utf8_repr, encoding, is_py3
|
||||||
|
|
||||||
|
|
||||||
def search_ancestor(node, node_type_or_types):
|
def search_ancestor(node, *node_types):
|
||||||
"""
|
"""
|
||||||
Recursively looks at the parents of a node and checks if the type names
|
Recursively looks at the parents of a node and checks if the type names
|
||||||
match.
|
match.
|
||||||
|
|
||||||
:param node: The node that is looked at.
|
:param node: The node that is looked at.
|
||||||
:param node_type_or_types: A tuple or a string of type names that are
|
:param node_types: A tuple or a string of type names that are
|
||||||
searched for.
|
searched for.
|
||||||
"""
|
"""
|
||||||
if not isinstance(node_type_or_types, (list, tuple)):
|
|
||||||
node_type_or_types = (node_type_or_types,)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
node = node.parent
|
node = node.parent
|
||||||
if node is None or node.type in node_type_or_types:
|
if node is None or node.type in node_types:
|
||||||
return node
|
return node
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user