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