Avoid the need to import search_ancestor

This commit is contained in:
Dave Halter
2026-01-19 20:30:03 +01:00
parent 4a7b5f4879
commit 3ac1632a5c
13 changed files with 28 additions and 44 deletions
+1 -1
View File
@@ -483,7 +483,7 @@ class Script:
module_context = self._get_module_context()
n = tree.search_ancestor(leaf, 'funcdef', 'classdef')
n = leaf.search_ancestor('funcdef', 'classdef')
if n is not None and n.start_pos < pos <= n.children[-1].start_pos:
# This is a bit of a special case. The context of a function/class
# name/param/keyword is always it's parent context, not the
+1 -3
View File
@@ -17,8 +17,6 @@ import re
from pathlib import Path
from typing import Optional
from parso.tree import search_ancestor
from jedi import settings
from jedi import debug
from jedi.inference.utils import unite
@@ -509,7 +507,7 @@ class BaseName:
# - param: The parent_context of a param is not its function but
# e.g. the outer class or module.
cls_or_func_node = self._name.tree_name.get_definition()
parent = search_ancestor(cls_or_func_node, 'funcdef', 'classdef', 'file_input')
parent = cls_or_func_node.search_ancestor('funcdef', 'classdef', 'file_input')
context = self._get_module_context().create_value(parent).as_context()
else:
context = self._name.parent_context
+5 -5
View File
@@ -4,7 +4,7 @@ from inspect import Parameter
from parso.python.token import PythonTokenTypes
from parso.python import tree
from parso.tree import search_ancestor, Leaf
from parso.tree import Leaf
from parso import split_lines
from jedi import debug
@@ -244,8 +244,8 @@ class Completion:
if previous_leaf is not None:
stmt = previous_leaf
while True:
stmt = search_ancestor(
stmt, 'if_stmt', 'for_stmt', 'while_stmt', 'try_stmt',
stmt = stmt.search_ancestor(
'if_stmt', 'for_stmt', 'while_stmt', 'try_stmt',
'error_node',
)
if stmt is None:
@@ -356,7 +356,7 @@ class Completion:
stack_node = self.stack[-3]
if stack_node.nonterminal == 'funcdef':
context = get_user_context(self._module_context, self._position)
node = search_ancestor(leaf, 'error_node', 'funcdef')
node = leaf.search_ancestor('error_node', 'funcdef')
if node is not None:
if node.type == 'error_node':
n = node.children[0]
@@ -426,7 +426,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 = tree.search_ancestor(leaf, 'classdef')
cls = leaf.search_ancestor('classdef')
if cls is None:
return