1
0
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:
Dave Halter
2017-05-02 19:19:07 +02:00
parent 6ea06fdfd8
commit 336b8a46d0
5 changed files with 8 additions and 11 deletions

View File

@@ -2,21 +2,18 @@ from abc import abstractmethod, abstractproperty
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
match.
: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.
"""
if not isinstance(node_type_or_types, (list, tuple)):
node_type_or_types = (node_type_or_types,)
while True:
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