mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-31 02:45:21 +08:00
Removed tree.is_node.
It's not needed anymore, because we have Node/Leaf.type now.
This commit is contained in:
@@ -269,7 +269,7 @@ class Evaluator(object):
|
||||
def _eval_element_not_cached(self, context, element):
|
||||
debug.dbg('eval_element %s@%s', element, element.start_pos)
|
||||
types = set()
|
||||
if isinstance(element, (tree.Name, tree.Literal)) or tree.is_node(element, 'atom'):
|
||||
if isinstance(element, (tree.Name, tree.Literal)) or element.type == 'atom':
|
||||
types = self.eval_atom(context, element)
|
||||
elif isinstance(element, tree.Keyword):
|
||||
# For False/True/None
|
||||
@@ -358,7 +358,7 @@ class Evaluator(object):
|
||||
return types
|
||||
# Parentheses without commas are not tuples.
|
||||
elif c[0] == '(' and not len(c) == 2 \
|
||||
and not(tree.is_node(c[1], 'testlist_comp') and
|
||||
and not(c[1].type == 'testlist_comp' and
|
||||
len(c[1].children) > 1):
|
||||
return self.eval_element(context, c[1])
|
||||
|
||||
@@ -508,7 +508,7 @@ class Evaluator(object):
|
||||
for value in values
|
||||
)
|
||||
|
||||
if tree.is_node(par, 'trailer') and par.children[0] == '.':
|
||||
if par.type == 'trailer' and par.children[0] == '.':
|
||||
values = helpers.evaluate_call_of_leaf(context, name, cut_own_trailer=True)
|
||||
return unite(
|
||||
value.py__getattribute__(name, name_context=context, is_goto=True)
|
||||
|
||||
@@ -427,9 +427,9 @@ class SequenceLiteralContext(ArrayMixin, AbstractSequence):
|
||||
if array_node in (']', '}', ')'):
|
||||
return [] # Direct closing bracket, doesn't contain items.
|
||||
|
||||
if tree.is_node(array_node, 'testlist_comp'):
|
||||
if array_node.type == 'testlist_comp':
|
||||
return array_node.children[::2]
|
||||
elif tree.is_node(array_node, 'dictorsetmaker'):
|
||||
elif array_node.type == 'dictorsetmaker':
|
||||
kv = []
|
||||
iterator = iter(array_node.children)
|
||||
for key in iterator:
|
||||
@@ -889,14 +889,14 @@ def create_index_types(evaluator, context, index):
|
||||
if index == ':':
|
||||
# Like array[:]
|
||||
return set([Slice(context, None, None, None)])
|
||||
elif tree.is_node(index, 'subscript'): # subscript is a slice operation.
|
||||
elif index.type == 'subscript': # subscript is a slice operation.
|
||||
# Like array[:3]
|
||||
result = []
|
||||
for el in index.children:
|
||||
if el == ':':
|
||||
if not result:
|
||||
result.append(None)
|
||||
elif tree.is_node(el, 'sliceop'):
|
||||
elif el.type == 'sliceop':
|
||||
if len(el.children) == 2:
|
||||
result.append(el.children[1])
|
||||
else:
|
||||
|
||||
@@ -90,10 +90,10 @@ class TreeArguments(AbstractArguments):
|
||||
for el in self.argument_node:
|
||||
yield 0, el
|
||||
else:
|
||||
if not (tree.is_node(self.argument_node, 'arglist') or (
|
||||
if not (self.argument_node.type == 'arglist' or (
|
||||
# in python 3.5 **arg is an argument, not arglist
|
||||
(tree.is_node(self.argument_node, 'argument') and
|
||||
self.argument_node.children[0] in ('*', '**')))):
|
||||
(self.argument_node.type == 'argument') and
|
||||
self.argument_node.children[0] in ('*', '**'))):
|
||||
yield 0, self.argument_node
|
||||
return
|
||||
|
||||
@@ -103,7 +103,7 @@ class TreeArguments(AbstractArguments):
|
||||
continue
|
||||
elif child in ('*', '**'):
|
||||
yield len(child.value), next(iterator)
|
||||
elif tree.is_node(child, 'argument') and \
|
||||
elif child.type == 'argument' and \
|
||||
child.children[0] in ('*', '**'):
|
||||
assert len(child.children) == 2
|
||||
yield len(child.children[0].value), child.children[1]
|
||||
@@ -130,7 +130,7 @@ class TreeArguments(AbstractArguments):
|
||||
for key, values in _star_star_dict(self.context, dct, el, func):
|
||||
yield key, values
|
||||
else:
|
||||
if tree.is_node(el, 'argument'):
|
||||
if el.type == 'argument':
|
||||
c = el.children
|
||||
if len(c) == 3: # Keyword argument.
|
||||
named_args.append((c[0].value, context.LazyTreeContext(self.context, c[2]),))
|
||||
@@ -149,7 +149,7 @@ class TreeArguments(AbstractArguments):
|
||||
|
||||
def as_tree_tuple_objects(self):
|
||||
for stars, argument in self._split():
|
||||
if tree.is_node(argument, 'argument'):
|
||||
if argument.type == 'argument':
|
||||
argument, default = argument.children[::2]
|
||||
else:
|
||||
default = None
|
||||
|
||||
@@ -129,7 +129,7 @@ def py__getitem__(context, typ, node):
|
||||
# should be replaced by that class. This is not 100%
|
||||
# airtight but I don't have a better idea to check that it's
|
||||
# actually the PEP-0484 typing module and not some other
|
||||
if tree.is_node(node, "subscriptlist"):
|
||||
if node.type == "subscriptlist":
|
||||
nodes = node.children[::2] # skip the commas
|
||||
else:
|
||||
nodes = [node]
|
||||
|
||||
@@ -45,7 +45,7 @@ def calculate_children(evaluator, context, children):
|
||||
types = context.eval_node(next(iterator))
|
||||
for operator in iterator:
|
||||
right = next(iterator)
|
||||
if tree.is_node(operator, 'comp_op'): # not in / is not
|
||||
if operator.type == 'comp_op': # not in / is not
|
||||
operator = ' '.join(str(c.value) for c in operator.children)
|
||||
|
||||
# handle lazy evaluation of and/or here.
|
||||
|
||||
@@ -100,7 +100,7 @@ def _paths_from_assignment(module_context, expr_stmt):
|
||||
for assignee, operator in zip(expr_stmt.children[::2], expr_stmt.children[1::2]):
|
||||
try:
|
||||
assert operator in ['=', '+=']
|
||||
assert tree.is_node(assignee, 'power', 'atom_expr') and \
|
||||
assert assignee.type in ('power', 'atom_expr') and \
|
||||
len(assignee.children) > 1
|
||||
c = assignee.children
|
||||
assert c[0].type == 'name' and c[0].value == 'sys'
|
||||
@@ -133,8 +133,8 @@ def _paths_from_list_modifications(module_path, trailer1, trailer2):
|
||||
""" extract the path from either "sys.path.append" or "sys.path.insert" """
|
||||
# Guarantee that both are trailers, the first one a name and the second one
|
||||
# a function execution with at least one param.
|
||||
if not (tree.is_node(trailer1, 'trailer') and trailer1.children[0] == '.'
|
||||
and tree.is_node(trailer2, 'trailer') and trailer2.children[0] == '('
|
||||
if not (trailer1.type == 'trailer' and trailer1.children[0] == '.'
|
||||
and trailer2.type == 'trailer' and trailer2.children[0] == '('
|
||||
and len(trailer2.children) == 3):
|
||||
return []
|
||||
|
||||
@@ -154,10 +154,10 @@ def _check_module(module_context):
|
||||
def get_sys_path_powers(names):
|
||||
for name in names:
|
||||
power = name.parent.parent
|
||||
if tree.is_node(power, 'power', 'atom_expr'):
|
||||
if power.type in ('power', 'atom_expr'):
|
||||
c = power.children
|
||||
if isinstance(c[0], tree.Name) and c[0].value == 'sys' \
|
||||
and tree.is_node(c[1], 'trailer'):
|
||||
and c[1].type == 'trailer':
|
||||
n = c[1].children[1]
|
||||
if isinstance(n, tree.Name) and n.value == 'path':
|
||||
yield name, power
|
||||
|
||||
@@ -41,7 +41,6 @@ import abc
|
||||
|
||||
from jedi._compatibility import (Python3Method, encoding, is_py3, utf8_repr,
|
||||
literal_eval, unicode)
|
||||
from jedi.parser.utils import underscore_memoization
|
||||
|
||||
|
||||
def _safe_literal_eval(value):
|
||||
@@ -62,15 +61,6 @@ def _safe_literal_eval(value):
|
||||
return ''
|
||||
|
||||
|
||||
def is_node(node, *symbol_names):
|
||||
try:
|
||||
type = node.type
|
||||
except AttributeError:
|
||||
return False
|
||||
else:
|
||||
return type in symbol_names
|
||||
|
||||
|
||||
def search_ancestor(node, node_type_or_types):
|
||||
if not isinstance(node_type_or_types, (list, tuple)):
|
||||
node_type_or_types = (node_type_or_types,)
|
||||
@@ -91,7 +81,7 @@ class DocstringMixin(object):
|
||||
node = self.children[0]
|
||||
elif isinstance(self, ClassOrFunc):
|
||||
node = self.children[self.children.index(':') + 1]
|
||||
if is_node(node, 'suite'): # Normally a suite
|
||||
if node.type == 'suite': # Normally a suite
|
||||
node = node.children[1] # -> NEWLINE stmt
|
||||
else: # ExprStmt
|
||||
simple_stmt = self.parent
|
||||
@@ -101,7 +91,7 @@ class DocstringMixin(object):
|
||||
return ''
|
||||
node = c[index - 1]
|
||||
|
||||
if is_node(node, 'simple_stmt'):
|
||||
if node.type == 'simple_stmt':
|
||||
node = node.children[0]
|
||||
|
||||
if node.type == 'string':
|
||||
@@ -203,7 +193,7 @@ class Base(object):
|
||||
node = self.parent
|
||||
compare = self
|
||||
while node is not None:
|
||||
if is_node(node, 'testlist_comp', 'testlist_star_expr', 'exprlist'):
|
||||
if node.type in ('testlist_comp', 'testlist_star_expr', 'exprlist'):
|
||||
for i, child in enumerate(node.children):
|
||||
if child == compare:
|
||||
indexes.insert(0, (int(i / 2), node))
|
||||
@@ -746,7 +736,7 @@ class Scope(BaseNode, DocstringMixin):
|
||||
for element in children:
|
||||
if isinstance(element, typ):
|
||||
elements.append(element)
|
||||
if is_node(element, 'suite', 'simple_stmt', 'decorated') \
|
||||
if element.type in ('suite', 'simple_stmt', 'decorated') \
|
||||
or isinstance(element, Flow):
|
||||
elements += scan(element.children)
|
||||
return elements
|
||||
@@ -807,7 +797,6 @@ class Module(Scope):
|
||||
self.path = None # Set later.
|
||||
|
||||
@property
|
||||
@underscore_memoization
|
||||
def name(self):
|
||||
""" This is used for the goto functions. """
|
||||
if self.path is None:
|
||||
@@ -869,8 +858,8 @@ class ClassOrFunc(Scope):
|
||||
|
||||
def get_decorators(self):
|
||||
decorated = self.parent
|
||||
if is_node(decorated, 'decorated'):
|
||||
if is_node(decorated.children[0], 'decorators'):
|
||||
if decorated.type == 'decorated':
|
||||
if decorated.children[0].type == 'decorators':
|
||||
return decorated.children[0].children
|
||||
else:
|
||||
return decorated.children[:1]
|
||||
@@ -1264,7 +1253,7 @@ class WithStmt(Flow):
|
||||
names = []
|
||||
for with_item in self.children[1:-2:2]:
|
||||
# Check with items for 'as' names.
|
||||
if is_node(with_item, 'with_item'):
|
||||
if with_item.type == 'with_item':
|
||||
names += _defined_names(with_item.children[2])
|
||||
return names
|
||||
|
||||
@@ -1272,7 +1261,7 @@ class WithStmt(Flow):
|
||||
node = name
|
||||
while True:
|
||||
node = node.parent
|
||||
if is_node(node, 'with_item'):
|
||||
if node.type == 'with_item':
|
||||
return node.children[0]
|
||||
|
||||
def nodes_to_execute(self, last_added=False):
|
||||
@@ -1332,7 +1321,7 @@ class ImportFrom(Import):
|
||||
for n in self.children[1:]:
|
||||
if n not in ('.', '...'):
|
||||
break
|
||||
if is_node(n, 'dotted_name'): # from x.y import
|
||||
if n.type == 'dotted_name': # from x.y import
|
||||
return n.children[::2]
|
||||
elif n == 'import': # from . import
|
||||
return []
|
||||
@@ -1357,7 +1346,7 @@ class ImportFrom(Import):
|
||||
elif last == '*':
|
||||
return # No names defined directly.
|
||||
|
||||
if is_node(last, 'import_as_names'):
|
||||
if last.type == 'import_as_names':
|
||||
as_names = last.children[::2]
|
||||
else:
|
||||
as_names = [last]
|
||||
@@ -1404,13 +1393,13 @@ class ImportName(Import):
|
||||
def _dotted_as_names(self):
|
||||
"""Generator of (list(path), alias) where alias may be None."""
|
||||
dotted_as_names = self.children[1]
|
||||
if is_node(dotted_as_names, 'dotted_as_names'):
|
||||
if dotted_as_names.type == 'dotted_as_names':
|
||||
as_names = dotted_as_names.children[::2]
|
||||
else:
|
||||
as_names = [dotted_as_names]
|
||||
|
||||
for as_name in as_names:
|
||||
if is_node(as_name, 'dotted_as_name'):
|
||||
if as_name.type == 'dotted_as_name':
|
||||
alias = as_name.children[2]
|
||||
as_name = as_name.children[0]
|
||||
else:
|
||||
@@ -1513,12 +1502,12 @@ def _defined_names(current):
|
||||
list comprehensions.
|
||||
"""
|
||||
names = []
|
||||
if is_node(current, 'testlist_star_expr', 'testlist_comp', 'exprlist'):
|
||||
if current.type in ('testlist_star_expr', 'testlist_comp', 'exprlist'):
|
||||
for child in current.children[::2]:
|
||||
names += _defined_names(child)
|
||||
elif is_node(current, 'atom', 'star_expr'):
|
||||
elif current.type in ('atom', 'star_expr'):
|
||||
names += _defined_names(current.children[1])
|
||||
elif is_node(current, 'power', 'atom_expr'):
|
||||
elif current.type in ('power', 'atom_expr'):
|
||||
if current.children[-2] != '**': # Just if there's no operation
|
||||
trailer = current.children[-1]
|
||||
if trailer.children[0] == '.':
|
||||
@@ -1594,7 +1583,7 @@ class Param(BaseNode):
|
||||
|
||||
def annotation(self):
|
||||
tfpdef = self._tfpdef()
|
||||
if is_node(tfpdef, 'tfpdef'):
|
||||
if tfpdef.type == 'tfpdef':
|
||||
assert tfpdef.children[1] == ":"
|
||||
assert len(tfpdef.children) == 3
|
||||
annotation = tfpdef.children[2]
|
||||
@@ -1611,7 +1600,7 @@ class Param(BaseNode):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
if is_node(self._tfpdef(), 'tfpdef'):
|
||||
if self._tfpdef().type == 'tfpdef':
|
||||
return self._tfpdef().children[0]
|
||||
else:
|
||||
return self._tfpdef()
|
||||
@@ -1644,7 +1633,7 @@ class CompFor(BaseNode):
|
||||
while True:
|
||||
if isinstance(last, CompFor):
|
||||
yield last
|
||||
elif not is_node(last, 'comp_if'):
|
||||
elif not last.type == 'comp_if':
|
||||
break
|
||||
last = last.children[-1]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user