Get rid of get_parent_until.

This commit is contained in:
Dave Halter
2017-02-03 09:59:32 +01:00
parent b3cb7b5490
commit 445bf6c419
9 changed files with 15 additions and 30 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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