1
0
forked from VimPlug/jedi

Replace pr with tree, #566.

This commit is contained in:
Dave Halter
2015-04-28 01:34:31 +02:00
parent 71547641ae
commit ef4b424cda
13 changed files with 138 additions and 138 deletions

View File

@@ -63,7 +63,7 @@ that are not used are just being ignored.
import copy
from itertools import chain
from jedi.parser import tree as pr
from jedi.parser import tree
from jedi import debug
from jedi.evaluate import representation as er
from jedi.evaluate import imports
@@ -91,14 +91,14 @@ class Evaluator(object):
self.analysis = []
def wrap(self, element):
if isinstance(element, pr.Class):
if isinstance(element, tree.Class):
return er.Class(self, element)
elif isinstance(element, pr.Function):
if isinstance(element, pr.Lambda):
elif isinstance(element, tree.Function):
if isinstance(element, tree.Lambda):
return er.LambdaWrapper(self, element)
else:
return er.Function(self, element)
elif isinstance(element, (pr.Module)) \
elif isinstance(element, (tree.Module)) \
and not isinstance(element, er.ModuleWrapper):
return er.ModuleWrapper(self, element)
else:
@@ -130,7 +130,7 @@ class Evaluator(object):
names are defined in the statement, `seek_name` returns the result for
this name.
:param stmt: A `pr.ExprStmt`.
:param stmt: A `tree.ExprStmt`.
"""
debug.dbg('eval_statement %s (%s)', stmt, seek_name)
types = self.eval_element(stmt.get_rhs())
@@ -146,7 +146,7 @@ class Evaluator(object):
name = str(stmt.get_defined_names()[0])
parent = self.wrap(stmt.get_parent_scope())
left = self.find_types(parent, name, stmt.start_pos, search_global=True)
if isinstance(stmt.get_parent_until(pr.ForStmt), pr.ForStmt):
if isinstance(stmt.get_parent_until(tree.ForStmt), tree.ForStmt):
# Iterate through result and add the values, that's possible
# only in for loops without clutter, because they are
# predictable.
@@ -166,15 +166,15 @@ class Evaluator(object):
return iterable.unite(self.eval_element(e) for e in element)
debug.dbg('eval_element %s@%s', element, element.start_pos)
if isinstance(element, (pr.Name, pr.Literal)) or pr.is_node(element, 'atom'):
if isinstance(element, (tree.Name, tree.Literal)) or tree.is_node(element, 'atom'):
return self._eval_atom(element)
elif isinstance(element, pr.Keyword):
elif isinstance(element, tree.Keyword):
# For False/True/None
if element.value in ('False', 'True', 'None'):
return [compiled.builtin.get_by_name(element.value)]
else:
return []
elif element.isinstance(pr.Lambda):
elif element.isinstance(tree.Lambda):
return [er.LambdaWrapper(self, element)]
elif element.isinstance(er.LambdaWrapper):
return [element] # TODO this is no real evaluation.
@@ -218,24 +218,24 @@ class Evaluator(object):
generate the node (because it has just one child). In that case an atom
might be a name or a literal as well.
"""
if isinstance(atom, pr.Name):
if isinstance(atom, tree.Name):
# This is the first global lookup.
stmt = atom.get_definition()
scope = stmt.get_parent_until(pr.IsScope, include_current=True)
if isinstance(stmt, pr.CompFor):
stmt = stmt.get_parent_until((pr.ClassOrFunc, pr.ExprStmt))
scope = stmt.get_parent_until(tree.IsScope, include_current=True)
if isinstance(stmt, tree.CompFor):
stmt = stmt.get_parent_until((tree.ClassOrFunc, tree.ExprStmt))
if stmt.type != 'expr_stmt':
# We only need to adjust the start_pos for statements, because
# there the name cannot be used.
stmt = atom
return self.find_types(scope, atom, stmt.start_pos, search_global=True)
elif isinstance(atom, pr.Literal):
elif isinstance(atom, tree.Literal):
return [compiled.create(self, atom.eval())]
else:
c = atom.children
# Parentheses without commas are not tuples.
if c[0] == '(' and not len(c) == 2 \
and not(pr.is_node(c[1], 'testlist_comp')
and not(tree.is_node(c[1], 'testlist_comp')
and len(c[1].children) > 1):
return self.eval_element(c[1])
try:
@@ -243,7 +243,7 @@ class Evaluator(object):
except (IndexError, AttributeError):
pass
else:
if isinstance(comp_for, pr.CompFor):
if isinstance(comp_for, tree.CompFor):
return [iterable.Comprehension.from_atom(self, atom)]
return [iterable.Array(self, atom)]
@@ -345,13 +345,13 @@ class Evaluator(object):
param_names += [param.name for param in params
if param.name.value == name.value]
return param_names
elif isinstance(par, pr.ExprStmt) and name in par.get_defined_names():
elif isinstance(par, tree.ExprStmt) and name in par.get_defined_names():
# Only take the parent, because if it's more complicated than just
# a name it's something you can "goto" again.
return [name]
elif isinstance(par, (pr.Param, pr.Function, pr.Class)) and par.name is name:
elif isinstance(par, (tree.Param, tree.Function, tree.Class)) and par.name is name:
return [name]
elif isinstance(stmt, pr.Import):
elif isinstance(stmt, tree.Import):
modules = imports.ImportWrapper(self, name).follow(is_goto=True)
return list(resolve_implicit_imports(modules))
elif par.type == 'dotted_name': # Is a decorator.
@@ -365,7 +365,7 @@ class Evaluator(object):
))
scope = name.get_parent_scope()
if pr.is_node(name.parent, 'trailer'):
if tree.is_node(name.parent, 'trailer'):
call = helpers.call_of_name(name, cut_own_trailer=True)
types = self.eval_element(call)
return resolve_implicit_imports(iterable.unite(

View File

@@ -2,7 +2,7 @@
Module for statical analysis.
"""
from jedi import debug
from jedi.parser import tree as pr
from jedi.parser import tree
from jedi.evaluate.compiled import CompiledObject
@@ -196,13 +196,13 @@ def _check_for_exception_catch(evaluator, jedi_obj, exception, payload=None):
return False
obj = jedi_obj
while obj is not None and not obj.isinstance(pr.Function, pr.Class):
if obj.isinstance(pr.Flow):
while obj is not None and not obj.isinstance(tree.Function, tree.Class):
if obj.isinstance(tree.Flow):
# try/except catch check
if obj.isinstance(pr.TryStmt) and check_try_for_except(obj, exception):
if obj.isinstance(tree.TryStmt) and check_try_for_except(obj, exception):
return True
# hasattr check
if exception == AttributeError and obj.isinstance(pr.IfStmt, pr.WhileStmt):
if exception == AttributeError and obj.isinstance(tree.IfStmt, tree.WhileStmt):
if check_hasattr(obj.children[1], obj.children[3]):
return True
obj = obj.parent
@@ -243,7 +243,7 @@ def get_module_statements(module):
def add_nodes(nodes):
new = set()
for node in nodes:
if isinstance(node, pr.Flow):
if isinstance(node, tree.Flow):
children = node.children
if node.type == 'for_stmt':
children = children[2:] # Don't want to include the names.
@@ -258,7 +258,7 @@ def get_module_statements(module):
pass
elif node.type not in ('whitespace', 'operator', 'keyword',
'parameters', 'decorated', 'except_clause') \
and not isinstance(node, (pr.ClassOrFunc, pr.Import)):
and not isinstance(node, (tree.ClassOrFunc, tree.Import)):
new.add(node)
try:
@@ -282,7 +282,7 @@ def get_module_statements(module):
import_names |= set(path[-1] for path in imp.paths())
children = scope.children
if isinstance(scope, pr.ClassOrFunc):
if isinstance(scope, tree.ClassOrFunc):
children = children[2:] # We don't want to include the class name.
nodes |= add_nodes(children)

View File

@@ -19,7 +19,7 @@ It works as follows:
from itertools import chain
from jedi._compatibility import unicode
from jedi.parser import tree as pr
from jedi.parser import tree
from jedi import settings
from jedi import debug
from jedi.evaluate.cache import memoize_default
@@ -55,7 +55,7 @@ def search_params(evaluator, param):
return []
debug.dbg('Dynamic param search for %s', param)
func = param.get_parent_until(pr.Function)
func = param.get_parent_until(tree.Function)
# Compare the param names.
names = [n for n in search_function_call(evaluator, func)
if n.value == param.name.value]
@@ -85,11 +85,11 @@ def search_function_call(evaluator, func):
for name in names:
parent = name.parent
if pr.is_node(parent, 'trailer'):
if tree.is_node(parent, 'trailer'):
parent = parent.parent
trailer = None
if pr.is_node(parent, 'power'):
if tree.is_node(parent, 'power'):
for t in parent.children[1:]:
if t == '**':
break
@@ -124,7 +124,7 @@ def search_function_call(evaluator, func):
compare = func
if func_name == '__init__':
cls = func.get_parent_scope()
if isinstance(cls, pr.Class):
if isinstance(cls, tree.Class):
func_name = unicode(cls.name)
compare = cls

View File

@@ -14,7 +14,7 @@ check for -> a is a string). There's big potential in these checks.
from itertools import chain
from jedi._compatibility import unicode, u
from jedi.parser import tree as pr
from jedi.parser import tree
from jedi import debug
from jedi import common
from jedi import settings
@@ -43,7 +43,7 @@ def filter_after_position(names, position):
for n in names:
# Filter positions and also allow list comprehensions and lambdas.
if n.start_pos[0] is not None and n.start_pos < position \
or isinstance(n.get_definition(), (pr.CompFor, pr.Lambda)):
or isinstance(n.get_definition(), (tree.CompFor, tree.Lambda)):
names_new.append(n)
return names_new
@@ -87,8 +87,8 @@ class NameFinder(object):
types = self._names_to_types(names, search_global)
if not names and not types \
and not (isinstance(self.name_str, pr.Name)
and isinstance(self.name_str.parent.parent, pr.Param)):
and not (isinstance(self.name_str, tree.Name)
and isinstance(self.name_str.parent.parent, tree.Param)):
if not isinstance(self.name_str, (str, unicode)): # TODO Remove?
if search_global:
message = ("NameError: name '%s' is not defined."
@@ -110,7 +110,7 @@ class NameFinder(object):
def names_dict_lookup(self, names_dict, position):
def get_param(scope, el):
if isinstance(el.get_parent_until(pr.Param), pr.Param):
if isinstance(el.get_parent_until(tree.Param), tree.Param):
return scope.param_by_name(str(el))
return el
@@ -148,8 +148,8 @@ class NameFinder(object):
last_names.append(name)
continue
if isinstance(self.name_str, pr.Name):
origin_scope = self.name_str.get_parent_until(pr.Scope, reverse=True)
if isinstance(self.name_str, tree.Name):
origin_scope = self.name_str.get_parent_until(tree.Scope, reverse=True)
else:
origin_scope = None
if isinstance(stmt.parent, compiled.CompiledObject):
@@ -190,7 +190,7 @@ class NameFinder(object):
"""
for n in names:
definition = n.parent
if isinstance(definition, (pr.Function, pr.Class, pr.Module)):
if isinstance(definition, (tree.Function, tree.Class, tree.Module)):
yield self._evaluator.wrap(definition).name
else:
yield n
@@ -215,7 +215,7 @@ class NameFinder(object):
types = []
# Add isinstance and other if/assert knowledge.
if isinstance(self.name_str, pr.Name):
if isinstance(self.name_str, tree.Name):
# Ignore FunctionExecution parents for now.
flow_scope = self.name_str
until = flow_scope.get_parent_until(er.FunctionExecution)
@@ -246,7 +246,7 @@ class NameFinder(object):
# definition. __get__ is only called if the descriptor is defined in
# the class dictionary.
name_scope = name.get_definition().get_parent_scope()
if not isinstance(name_scope, (er.Instance, pr.Class)):
if not isinstance(name_scope, (er.Instance, tree.Class)):
return types
result = []
@@ -264,23 +264,23 @@ class NameFinder(object):
def _name_to_types(evaluator, name, scope):
types = []
typ = name.get_definition()
if typ.isinstance(pr.ForStmt):
if typ.isinstance(tree.ForStmt):
for_types = evaluator.eval_element(typ.children[3])
for_types = iterable.get_iterator_types(for_types)
types += check_tuple_assignments(for_types, name)
elif typ.isinstance(pr.CompFor):
elif typ.isinstance(tree.CompFor):
for_types = evaluator.eval_element(typ.children[3])
for_types = iterable.get_iterator_types(for_types)
types += check_tuple_assignments(for_types, name)
elif isinstance(typ, pr.Param):
elif isinstance(typ, tree.Param):
types += _eval_param(evaluator, typ, scope)
elif typ.isinstance(pr.ExprStmt):
elif typ.isinstance(tree.ExprStmt):
types += _remove_statements(evaluator, typ, name)
elif typ.isinstance(pr.WithStmt):
elif typ.isinstance(tree.WithStmt):
types += evaluator.eval_element(typ.node_from_name(name))
elif isinstance(typ, pr.Import):
elif isinstance(typ, tree.Import):
types += imports.ImportWrapper(evaluator, name).follow()
elif isinstance(typ, pr.GlobalStmt):
elif isinstance(typ, tree.GlobalStmt):
# TODO theoretically we shouldn't be using search_global here, it
# doesn't make sense, because it's a local search (for that name)!
# However, globals are not that important and resolving them doesn't
@@ -288,7 +288,7 @@ def _name_to_types(evaluator, name, scope):
# something is executed.
types += evaluator.find_types(typ.get_parent_scope(), str(name),
search_global=True)
elif isinstance(typ, pr.TryStmt):
elif isinstance(typ, tree.TryStmt):
# TODO an exception can also be a tuple. Check for those.
# TODO check for types that are not classes and add it to
# the static analysis report.
@@ -325,7 +325,7 @@ def _remove_statements(evaluator, stmt, name):
if check_instance is not None:
# class renames
types = [er.get_instance_el(evaluator, check_instance, a, True)
if isinstance(a, (er.Function, pr.Function))
if isinstance(a, (er.Function, tree.Function))
else a for a in types]
return types
@@ -334,10 +334,10 @@ def _eval_param(evaluator, param, scope):
res_new = []
func = param.get_parent_scope()
cls = func.parent.get_parent_until((pr.Class, pr.Function))
cls = func.parent.get_parent_until((tree.Class, tree.Function))
from jedi.evaluate.param import ExecutedParam, Arguments
if isinstance(cls, pr.Class) and param.position_nr == 0 \
if isinstance(cls, tree.Class) and param.position_nr == 0 \
and not isinstance(param, ExecutedParam):
# This is where we add self - if it has never been
# instantiated.
@@ -396,13 +396,13 @@ def check_flow_information(evaluator, flow, search_name, pos):
names = []
for name in names:
ass = name.get_parent_until(pr.AssertStmt)
if isinstance(ass, pr.AssertStmt) and pos is not None and ass.start_pos < pos:
ass = name.get_parent_until(tree.AssertStmt)
if isinstance(ass, tree.AssertStmt) and pos is not None and ass.start_pos < pos:
result = _check_isinstance_type(evaluator, ass.assertion(), search_name)
if result:
break
if isinstance(flow, (pr.IfStmt, pr.WhileStmt)):
if isinstance(flow, (tree.IfStmt, tree.WhileStmt)):
element = flow.children[1]
result = _check_isinstance_type(evaluator, element, search_name)
return result
@@ -414,7 +414,7 @@ def _check_isinstance_type(evaluator, element, search_name):
# this might be removed if we analyze and, etc
assert len(element.children) == 2
first, trailer = element.children
assert isinstance(first, pr.Name) and first.value == 'isinstance'
assert isinstance(first, tree.Name) and first.value == 'isinstance'
assert trailer.type == 'trailer' and trailer.children[0] == '('
assert len(trailer.children) == 3
@@ -536,7 +536,7 @@ def filter_private_variable(scope, origin_node):
instance = scope.get_parent_scope()
coming_from = origin_node
while coming_from is not None \
and not isinstance(coming_from, (pr.Class, compiled.CompiledObject)):
and not isinstance(coming_from, (tree.Class, compiled.CompiledObject)):
coming_from = coming_from.get_parent_scope()
# CompiledObjects don't have double underscore attributes, but Jedi abuses

View File

@@ -1,4 +1,4 @@
from jedi.parser import tree as pr
from jedi.parser import tree
class Status(object):
@@ -53,7 +53,7 @@ def _break_check(evaluator, stmt, base_scope, element_scope):
base_scope = evaluator.wrap(base_scope)
reachable = REACHABLE
if isinstance(element_scope, pr.IfStmt):
if isinstance(element_scope, tree.IfStmt):
if element_scope.node_after_else(stmt):
for check_node in element_scope.check_nodes():
reachable = _check_if(evaluator, check_node)
@@ -63,7 +63,7 @@ def _break_check(evaluator, stmt, base_scope, element_scope):
else:
node = element_scope.node_in_which_check_node(stmt)
reachable = _check_if(evaluator, node)
elif isinstance(element_scope, (pr.TryStmt, pr.WhileStmt)):
elif isinstance(element_scope, (tree.TryStmt, tree.WhileStmt)):
return UNSURE
# Only reachable branches need to be examined further.

View File

@@ -1,7 +1,7 @@
import copy
from itertools import chain
from jedi.parser import tree as pr
from jedi.parser import tree
def deep_ast_copy(obj, parent=None, new_elements=None):
@@ -60,11 +60,11 @@ def deep_ast_copy(obj, parent=None, new_elements=None):
new_elements[obj] = new_obj = copy.copy(obj)
if parent is not None:
new_obj.parent = parent
elif isinstance(obj, pr.BaseNode):
elif isinstance(obj, tree.BaseNode):
new_obj = copy_node(obj)
if parent is not None:
for child in new_obj.children:
if isinstance(child, (pr.Name, pr.BaseNode)):
if isinstance(child, (tree.Name, tree.BaseNode)):
child.parent = parent
else: # String literals and so on.
new_obj = obj # Good enough, don't need to copy anything.
@@ -83,11 +83,11 @@ def call_of_name(name, cut_own_trailer=False):
This generates a copy of the original ast node.
"""
par = name
if pr.is_node(par.parent, 'trailer'):
if tree.is_node(par.parent, 'trailer'):
par = par.parent
power = par.parent
if pr.is_node(power, 'power') and power.children[0] != name \
if tree.is_node(power, 'power') and power.children[0] != name \
and not (power.children[-2] == '**' and
name.start_pos > power.children[-1].start_pos):
par = power
@@ -117,7 +117,7 @@ def get_module_names(module, all_scopes):
return chain.from_iterable(dct.values())
class FakeImport(pr.ImportName):
class FakeImport(tree.ImportName):
def __init__(self, name, parent, level=0):
super(FakeImport, self).__init__([])
self.parent = parent
@@ -145,13 +145,13 @@ class FakeImport(pr.ImportName):
return True
class FakeName(pr.Name):
class FakeName(tree.Name):
def __init__(self, name_str, parent=None, start_pos=(0, 0), is_definition=None):
"""
In case is_definition is defined (not None), that bool value will be
returned.
"""
super(FakeName, self).__init__(pr.zero_position_modifier, name_str, start_pos)
super(FakeName, self).__init__(tree.zero_position_modifier, name_str, start_pos)
self.parent = parent
self._is_definition = is_definition

View File

@@ -22,7 +22,7 @@ from jedi import common
from jedi import debug
from jedi import cache
from jedi.parser import fast
from jedi.parser import tree as pr
from jedi.parser import tree
from jedi.evaluate import sys_path
from jedi.evaluate import helpers
from jedi import settings
@@ -50,7 +50,7 @@ def completion_names(evaluator, imp, pos):
level = imp.level
importer = get_importer(evaluator, tuple(import_path), module, level)
if isinstance(imp, pr.ImportFrom):
if isinstance(imp, tree.ImportFrom):
c = imp.children
only_modules = c[c.index('import')].start_pos >= pos
else:
@@ -58,12 +58,12 @@ def completion_names(evaluator, imp, pos):
return importer.completion_names(evaluator, only_modules)
class ImportWrapper(pr.Base):
class ImportWrapper(tree.Base):
def __init__(self, evaluator, name):
self._evaluator = evaluator
self._name = name
self._import = name.get_parent_until(pr.Import)
self._import = name.get_parent_until(tree.Import)
self.import_path = self._import.path_for_name(name)
@memoize_default()
@@ -138,7 +138,7 @@ class ImportWrapper(pr.Base):
return types
class NestedImportModule(pr.Module):
class NestedImportModule(tree.Module):
"""
TODO while there's no use case for nested import module right now, we might
be able to use them for static analysis checks later on.
@@ -157,7 +157,7 @@ class NestedImportModule(pr.Module):
zero = (0, 0)
names = [unicode(name) for name in i.namespace_names[1:]]
name = helpers.FakeName(names, self._nested_import)
new = pr.Import(i._sub_module, zero, zero, name)
new = tree.Import(i._sub_module, zero, zero, name)
new.parent = self._module
debug.dbg('Generated a nested import: %s', new)
return helpers.FakeName(str(i.namespace_names[1]), new)
@@ -462,7 +462,7 @@ class _Importer(object):
continue
# namespace packages
if isinstance(scope, pr.Module) and scope.path.endswith('__init__.py'):
if isinstance(scope, tree.Module) and scope.path.endswith('__init__.py'):
pkg_path = os.path.dirname(scope.path)
paths = self.namespace_packages(pkg_path, self.import_path)
names += self._get_module_names([pkg_path] + paths)

View File

@@ -26,7 +26,7 @@ from jedi import common
from jedi import debug
from jedi import settings
from jedi._compatibility import use_metaclass, is_py3, unicode
from jedi.parser import tree as pr
from jedi.parser import tree
from jedi.evaluate import compiled
from jedi.evaluate import helpers
from jedi.evaluate.cache import CachedMetaClass, memoize_default
@@ -38,7 +38,7 @@ def unite(iterable):
return list(chain.from_iterable(iterable))
class IterableWrapper(pr.Base):
class IterableWrapper(tree.Base):
def is_class(self):
return False
@@ -140,9 +140,9 @@ class Comprehension(IterableWrapper):
last = comprehension.children[-1]
last_comp = comprehension.children[1]
while True:
if isinstance(last, pr.CompFor):
if isinstance(last, tree.CompFor):
last_comp = last
elif not pr.is_node(last, 'comp_if'):
elif not tree.is_node(last, 'comp_if'):
break
last = last.children[-1]
@@ -283,9 +283,9 @@ class Array(IterableWrapper, ArrayMixin):
if array_node in (']', '}', ')'):
return [] # Direct closing bracket, doesn't contain items.
if pr.is_node(array_node, 'testlist_comp'):
if tree.is_node(array_node, 'testlist_comp'):
return array_node.children[::2]
elif pr.is_node(array_node, 'dictorsetmaker'):
elif tree.is_node(array_node, 'dictorsetmaker'):
kv = []
iterator = iter(array_node.children)
for key in iterator:
@@ -613,14 +613,14 @@ class Slice(object):
def create_indexes_or_slices(evaluator, index):
if pr.is_node(index, 'subscript'): # subscript is a slice operation.
if tree.is_node(index, 'subscript'): # subscript is a slice operation.
start, stop, step = None, None, None
result = []
for el in index.children:
if el == ':':
if not result:
result.append(None)
elif pr.is_node(el, 'sliceop'):
elif tree.is_node(el, 'sliceop'):
if len(el.children) == 2:
result.append(el.children[1])
else:

View File

@@ -4,7 +4,7 @@ from itertools import chain
from jedi._compatibility import unicode, zip_longest
from jedi import debug
from jedi import common
from jedi.parser import tree as pr
from jedi.parser import tree
from jedi.evaluate import iterable
from jedi.evaluate import analysis
from jedi.evaluate import precedence
@@ -12,7 +12,7 @@ from jedi.evaluate.helpers import FakeName
from jedi.cache import underscore_memoization
class Arguments(pr.Base):
class Arguments(tree.Base):
def __init__(self, evaluator, argument_node, trailer=None):
"""
The argument_node is either a parser node or a list of evaluated
@@ -30,7 +30,7 @@ class Arguments(pr.Base):
for el in self.argument_node:
yield 0, el
else:
if not pr.is_node(self.argument_node, 'arglist'):
if not tree.is_node(self.argument_node, 'arglist'):
yield 0, self.argument_node
return
@@ -59,7 +59,7 @@ class Arguments(pr.Base):
def as_tuple(self):
for stars, argument in self._split():
if pr.is_node(argument, 'argument'):
if tree.is_node(argument, 'argument'):
argument, default = argument.children[::2]
else:
default = None
@@ -83,7 +83,7 @@ class Arguments(pr.Base):
for key, values in dct.items():
yield key, values
else:
if pr.is_node(el, 'argument'):
if tree.is_node(el, 'argument'):
c = el.children
if len(c) == 3: # Keyword argument.
named_args.append((c[0].value, (c[2],)))
@@ -106,7 +106,7 @@ class Arguments(pr.Base):
named_index = None
new_args = []
for i, stmt in enumerate(var_args):
if isinstance(stmt, pr.ExprStmt):
if isinstance(stmt, tree.ExprStmt):
if named_index is None and stmt.assignment_details:
named_index = i
@@ -143,7 +143,7 @@ class Arguments(pr.Base):
def scope(self):
# Returns the scope in which the arguments are used.
return (self.trailer or self.argument_node).get_parent_until(pr.IsScope)
return (self.trailer or self.argument_node).get_parent_until(tree.IsScope)
def eval_args(self):
# TODO this method doesn't work with named args and a lot of other
@@ -154,14 +154,14 @@ class Arguments(pr.Base):
return '<%s: %s>' % (type(self).__name__, self.argument_node)
def get_calling_var_args(self):
if pr.is_node(self.argument_node, 'arglist', 'argument') \
if tree.is_node(self.argument_node, 'arglist', 'argument') \
or self.argument_node == () and self.trailer is not None:
return _get_calling_var_args(self._evaluator, self)
else:
return None
class ExecutedParam(pr.Param):
class ExecutedParam(tree.Param):
"""Fake a param and give it values."""
def __init__(self, original_param, var_args, values):
self._original_param = original_param
@@ -193,7 +193,7 @@ def _get_calling_var_args(evaluator, var_args):
while var_args != old_var_args:
old_var_args = var_args
for name, default, stars in reversed(list(var_args.as_tuple())):
if not stars or not isinstance(name, pr.Name):
if not stars or not isinstance(name, tree.Name):
continue
names = evaluator.goto(name)
@@ -201,7 +201,7 @@ def _get_calling_var_args(evaluator, var_args):
break
param = names[0].get_definition()
if not isinstance(param, ExecutedParam):
if isinstance(param, pr.Param):
if isinstance(param, tree.Param):
# There is no calling var_args in this case - there's just
# a param without any input.
return None

View File

@@ -4,7 +4,7 @@ Handles operator precedence.
import operator
from jedi._compatibility import unicode
from jedi.parser import tree as pr
from jedi.parser import tree
from jedi import debug
from jedi.evaluate.compiled import (CompiledObject, create, builtin,
keyword_from_value, true_obj, false_obj)
@@ -43,7 +43,7 @@ def calculate_children(evaluator, children):
types = evaluator.eval_element(next(iterator))
for operator in iterator:
right = next(iterator)
if pr.is_node(operator, 'comp_op'): # not in / is not
if tree.is_node(operator, 'comp_op'): # not in / is not
operator = ' '.join(str(c.value) for c in operator.children)
# handle lazy evaluation of and/or here.

View File

@@ -35,7 +35,7 @@ import re
from itertools import chain
from jedi._compatibility import use_metaclass, unicode, Python3Method
from jedi.parser import tree as pr
from jedi.parser import tree
from jedi import debug
from jedi import common
from jedi.cache import underscore_memoization, cache_star_import
@@ -50,7 +50,7 @@ from jedi.evaluate import flow_analysis
from jedi.evaluate import imports
class Executed(pr.Base):
class Executed(tree.Base):
"""
An instance is also an executable - because __init__ is called
:param var_args: The param input array, consist of a parser node or a list.
@@ -64,7 +64,7 @@ class Executed(pr.Base):
return True
def get_parent_until(self, *args, **kwargs):
return pr.Base.get_parent_until(self, *args, **kwargs)
return tree.Base.get_parent_until(self, *args, **kwargs)
@common.safe_property
def parent(self):
@@ -136,7 +136,7 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
# This loop adds the names of the self object, copies them and removes
# the self.
for sub in self.base.subscopes:
if isinstance(sub, pr.Class):
if isinstance(sub, tree.Class):
continue
# Get the self name, if there's one.
self_name = self._get_func_self_name(sub)
@@ -155,7 +155,7 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
for name in name_list:
if name.value == self_name and name.prev_sibling() is None:
trailer = name.next_sibling()
if pr.is_node(trailer, 'trailer') \
if tree.is_node(trailer, 'trailer') \
and len(trailer.children) == 2 \
and trailer.children[0] == '.':
name = trailer.children[1] # After dot.
@@ -246,9 +246,9 @@ class LazyInstanceDict(object):
return [self[key] for key in self._dct]
class InstanceName(pr.Name):
class InstanceName(tree.Name):
def __init__(self, origin_name, parent):
super(InstanceName, self).__init__(pr.zero_position_modifier,
super(InstanceName, self).__init__(tree.zero_position_modifier,
origin_name.value,
origin_name.start_pos)
self._origin_name = origin_name
@@ -267,19 +267,19 @@ def get_instance_el(evaluator, instance, var, is_class_var=False):
in quite a lot of cases, which includes Nodes like ``power``, that need to
know where a self name comes from for example.
"""
if isinstance(var, pr.Name):
if isinstance(var, tree.Name):
parent = get_instance_el(evaluator, instance, var.parent, is_class_var)
return InstanceName(var, parent)
elif var.type != 'funcdef' \
and isinstance(var, (Instance, compiled.CompiledObject, pr.Leaf,
pr.Module, FunctionExecution)):
and isinstance(var, (Instance, compiled.CompiledObject, tree.Leaf,
tree.Module, FunctionExecution)):
return var
var = evaluator.wrap(var)
return InstanceElement(evaluator, instance, var, is_class_var)
class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
class InstanceElement(use_metaclass(CachedMetaClass, tree.Base)):
"""
InstanceElement is a wrapper for any object, that is used as an instance
variable (e.g. self.variable or class methods).
@@ -295,7 +295,7 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
def parent(self):
par = self.var.parent
if isinstance(par, Class) and par == self.instance.base \
or isinstance(par, pr.Class) \
or isinstance(par, tree.Class) \
and par == self.instance.base.base:
par = self.instance
else:
@@ -304,10 +304,10 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
return par
def get_parent_until(self, *args, **kwargs):
return pr.BaseNode.get_parent_until(self, *args, **kwargs)
return tree.BaseNode.get_parent_until(self, *args, **kwargs)
def get_definition(self):
return self.get_parent_until((pr.ExprStmt, pr.IsScope, pr.Import))
return self.get_parent_until((tree.ExprStmt, tree.IsScope, tree.Import))
def get_decorated_func(self):
""" Needed because the InstanceElement should not be stripped """
@@ -367,7 +367,7 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
return "<%s of %s>" % (type(self).__name__, self.var)
class Wrapper(pr.Base):
class Wrapper(tree.Base):
def is_scope(self):
return True
@@ -383,7 +383,7 @@ class Wrapper(pr.Base):
class Class(use_metaclass(CachedMetaClass, Wrapper)):
"""
This class is not only important to extend `pr.Class`, it is also a
This class is not only important to extend `tree.Class`, it is also a
important for descriptors (if the descriptor methods are evaluated or not).
"""
def __init__(self, evaluator, base):
@@ -505,7 +505,7 @@ class Function(use_metaclass(CachedMetaClass, Wrapper)):
trailer = dec.children[2:-1]
if trailer:
# Create a trailer and evaluate it.
trailer = pr.Node('trailer', trailer)
trailer = tree.Node('trailer', trailer)
dec_results = self._evaluator.eval_trailer(dec_results, trailer)
if not len(dec_results):
@@ -629,7 +629,7 @@ class FunctionExecution(Executed):
def _get_params(self):
"""
This returns the params for an TODO and is injected as a
'hack' into the pr.Function class.
'hack' into the tree.Function class.
This needs to be here, because Instance can have __init__ functions,
which act the same way as normal functions.
"""
@@ -639,7 +639,7 @@ class FunctionExecution(Executed):
return [n for n in self._get_params() if str(n) == name][0]
def name_for_position(self, position):
return pr.Function.name_for_position(self, position)
return tree.Function.name_for_position(self, position)
def _copy_list(self, lst):
"""
@@ -671,22 +671,22 @@ class FunctionExecution(Executed):
@common.safe_property
@memoize_default([])
def returns(self):
return pr.Scope._search_in_scope(self, pr.ReturnStmt)
return tree.Scope._search_in_scope(self, tree.ReturnStmt)
@common.safe_property
@memoize_default([])
def yields(self):
return pr.Scope._search_in_scope(self, pr.YieldExpr)
return tree.Scope._search_in_scope(self, tree.YieldExpr)
@common.safe_property
@memoize_default([])
def statements(self):
return pr.Scope._search_in_scope(self, pr.ExprStmt)
return tree.Scope._search_in_scope(self, tree.ExprStmt)
@common.safe_property
@memoize_default([])
def subscopes(self):
return pr.Scope._search_in_scope(self, pr.Scope)
return tree.Scope._search_in_scope(self, tree.Scope)
def __repr__(self):
return "<%s of %s>" % (type(self).__name__, self.base)
@@ -702,7 +702,7 @@ class GlobalName(helpers.FakeName):
name.start_pos, is_definition=True)
class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
class ModuleWrapper(use_metaclass(CachedMetaClass, tree.Module, Wrapper)):
def __init__(self, evaluator, module):
self._evaluator = evaluator
self.base = self._module = module
@@ -729,7 +729,7 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
name = i.star_import_name()
new = imports.ImportWrapper(self._evaluator, name).follow()
for module in new:
if isinstance(module, pr.Module):
if isinstance(module, tree.Module):
modules += module.star_imports()
modules += new
return modules

View File

@@ -14,7 +14,7 @@ from jedi.evaluate import compiled
from jedi.evaluate import representation as er
from jedi.evaluate import iterable
from jedi.parser import Parser
from jedi.parser import tree as pr
from jedi.parser import tree
from jedi import debug
from jedi.evaluate import precedence
from jedi.evaluate import param
@@ -32,7 +32,7 @@ def execute(evaluator, obj, params):
else:
if obj.parent == compiled.builtin:
module_name = 'builtins'
elif isinstance(obj.parent, pr.Module):
elif isinstance(obj.parent, tree.Module):
module_name = str(obj.parent.name)
else:
module_name = ''
@@ -98,7 +98,7 @@ def builtins_getattr(evaluator, objects, names, defaults=None):
types = []
# follow the first param
for obj in objects:
if not isinstance(obj, (er.Instance, er.Class, pr.Module, compiled.CompiledObject)):
if not isinstance(obj, (er.Instance, er.Class, tree.Module, compiled.CompiledObject)):
debug.warning('getattr called without instance')
continue
@@ -130,13 +130,13 @@ class SuperInstance(er.Instance):
@argument_clinic('[type[, obj]], /', want_scope=True)
def builtins_super(evaluator, types, objects, scope):
# TODO make this able to detect multiple inheritance super
accept = (pr.Function, er.FunctionExecution)
accept = (tree.Function, er.FunctionExecution)
if scope.isinstance(*accept):
wanted = (pr.Class, er.Instance)
wanted = (tree.Class, er.Instance)
cls = scope.get_parent_until(accept + wanted,
include_current=False)
if isinstance(cls, wanted):
if isinstance(cls, pr.Class):
if isinstance(cls, tree.Class):
cls = er.Class(evaluator, cls)
elif isinstance(cls, er.Instance):
cls = cls.base

View File

@@ -3,7 +3,7 @@ import os
import sys
from jedi._compatibility import exec_function, unicode
from jedi.parser import tree as pr
from jedi.parser import tree
from jedi.parser import Parser
from jedi.evaluate.cache import memoize_default
from jedi import debug
@@ -71,7 +71,7 @@ def _paths_from_assignment(evaluator, expr_stmt):
for assignee, operator in zip(expr_stmt.children[::2], expr_stmt.children[1::2]):
try:
assert operator in ['=', '+=']
assert pr.is_node(assignee, 'power') and len(assignee.children) > 1
assert tree.is_node(assignee, 'power') and len(assignee.children) > 1
c = assignee.children
assert c[0].type == 'name' and c[0].value == 'sys'
trailer = c[1]
@@ -101,8 +101,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 (pr.is_node(trailer1, 'trailer') and trailer1.children[0] == '.'
and pr.is_node(trailer2, 'trailer') and trailer2.children[0] == '('
if not (tree.is_node(trailer1, 'trailer') and trailer1.children[0] == '.'
and tree.is_node(trailer2, 'trailer') and trailer2.children[0] == '('
and len(trailer2.children) == 3):
return []
@@ -120,12 +120,12 @@ def _check_module(evaluator, module):
def get_sys_path_powers(names):
for name in names:
power = name.parent.parent
if pr.is_node(power, 'power'):
if tree.is_node(power, 'power'):
c = power.children
if isinstance(c[0], pr.Name) and c[0].value == 'sys' \
and pr.is_node(c[1], 'trailer'):
if isinstance(c[0], tree.Name) and c[0].value == 'sys' \
and tree.is_node(c[1], 'trailer'):
n = c[1].children[1]
if isinstance(n, pr.Name) and n.value == 'path':
if isinstance(n, tree.Name) and n.value == 'path':
yield name, power
sys_path = list(get_sys_path()) # copy