forked from VimPlug/jedi
Get rid of get_parent_until.
This commit is contained in:
@@ -669,7 +669,7 @@ class CallSignature(Definition):
|
||||
Use :attr:`.module_name` for the module name.
|
||||
.. todo:: Remove!
|
||||
"""
|
||||
return self._executable.get_parent_until()
|
||||
return self._executable.get_root_node()
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s: %s index %s>' % \
|
||||
|
||||
@@ -235,7 +235,7 @@ class Completion:
|
||||
Autocomplete inherited methods when overriding in child class.
|
||||
"""
|
||||
leaf = self._module_node.get_leaf_for_position(self._position, include_prefixes=True)
|
||||
cls = leaf.get_parent_until(tree.Class)
|
||||
cls = tree.search_ancestor(leaf, 'classdef')
|
||||
if isinstance(cls, (tree.Class, tree.Function)):
|
||||
# Complete the methods that are defined in the super classes.
|
||||
random_context = self._module_context.create_context(
|
||||
|
||||
@@ -299,7 +299,7 @@ def cache_call_signatures(evaluator, context, bracket_leaf, code_lines, user_pos
|
||||
whole = '\n'.join(other_lines + [before_cursor])
|
||||
before_bracket = re.match(r'.*\(', whole, re.DOTALL)
|
||||
|
||||
module_path = bracket_leaf.get_parent_until().path
|
||||
module_path = bracket_leaf.get_root_node().path
|
||||
if module_path is None:
|
||||
yield None # Don't cache!
|
||||
else:
|
||||
|
||||
@@ -90,9 +90,6 @@ class Keyword(object):
|
||||
self.start_pos = pos
|
||||
self.parent = evaluator.BUILTINS
|
||||
|
||||
def get_parent_until(self):
|
||||
return self.parent
|
||||
|
||||
@property
|
||||
def only_valid_as_leaf(self):
|
||||
return self.name.value in keywords_only_valid_as_leaf
|
||||
|
||||
@@ -161,7 +161,7 @@ class Evaluator(object):
|
||||
left = context.py__getattribute__(
|
||||
name, position=stmt.start_pos, search_global=True)
|
||||
|
||||
for_stmt = stmt.get_parent_until(tree.ForStmt)
|
||||
for_stmt = tree.search_ancestor(stmt, 'for_stmt')
|
||||
if isinstance(for_stmt, tree.ForStmt) and types \
|
||||
and for_stmt.defines_one_name():
|
||||
# Iterate through result and add the values, that's possible
|
||||
@@ -335,8 +335,8 @@ class Evaluator(object):
|
||||
# This is the first global lookup.
|
||||
stmt = atom.get_definition()
|
||||
if isinstance(stmt, tree.CompFor):
|
||||
stmt = stmt.get_parent_until((tree.ClassOrFunc, tree.ExprStmt))
|
||||
if stmt.type != 'expr_stmt':
|
||||
stmt = tree.search_ancestor(stmt, ('expr_stmt', 'lambda', 'funcdef', 'classdef'))
|
||||
if stmt is None or stmt.type != 'expr_stmt':
|
||||
# We only need to adjust the start_pos for statements, because
|
||||
# there the name cannot be used.
|
||||
stmt = atom
|
||||
|
||||
@@ -78,7 +78,13 @@ class NameFinder(object):
|
||||
|
||||
def _get_origin_scope(self):
|
||||
if isinstance(self._name, tree.Name):
|
||||
return self._name.get_parent_until(tree.Scope, reverse=True)
|
||||
scope = self._name
|
||||
while scope.parent is not None:
|
||||
# TODO why if classes?
|
||||
if not isinstance(scope, tree.Scope):
|
||||
break
|
||||
scope = scope.parent
|
||||
return scope
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ from jedi.evaluate.filters import AbstractNameDefinition
|
||||
@memoize_default(default=set())
|
||||
def infer_import(context, tree_name, is_goto=False):
|
||||
module_context = context.get_root_context()
|
||||
import_node = tree_name.get_parent_until(tree.Import)
|
||||
import_node = tree.search_ancestor(tree_name, ('import_name', 'import_from'))
|
||||
import_path = import_node.path_for_name(tree_name)
|
||||
from_import_name = None
|
||||
evaluator = context.evaluator
|
||||
|
||||
@@ -69,7 +69,7 @@ def _fix_forward_reference(context, node):
|
||||
debug.warning('Annotation not parsed: %s' % evaled_node.obj)
|
||||
return node
|
||||
else:
|
||||
module = node.get_parent_until()
|
||||
module = node.get_root_node()
|
||||
new_node.move(module.end_pos[0])
|
||||
new_node.parent = context.tree_node
|
||||
return new_node
|
||||
|
||||
@@ -126,24 +126,6 @@ class Base(object):
|
||||
scope = scope.parent
|
||||
return scope
|
||||
|
||||
@Python3Method
|
||||
def get_parent_until(self, classes=(), reverse=False,
|
||||
include_current=True):
|
||||
"""
|
||||
Searches the parent "chain" until the object is an instance of
|
||||
classes. If classes is empty return the last parent in the chain
|
||||
(is without a parent).
|
||||
"""
|
||||
if type(classes) not in (tuple, list):
|
||||
classes = (classes,)
|
||||
scope = self if include_current else self.parent
|
||||
while scope.parent is not None:
|
||||
# TODO why if classes?
|
||||
if classes and reverse != isinstance(scope, classes):
|
||||
break
|
||||
scope = scope.parent
|
||||
return scope
|
||||
|
||||
def get_parent_scope(self, include_flows=False):
|
||||
"""
|
||||
Returns the underlying scope.
|
||||
|
||||
Reference in New Issue
Block a user