forked from VimPlug/jedi
Replace pr with tree, #566.
This commit is contained in:
@@ -63,7 +63,7 @@ that are not used are just being ignored.
|
|||||||
import copy
|
import copy
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from jedi.parser import tree as pr
|
from jedi.parser import tree
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.evaluate import representation as er
|
from jedi.evaluate import representation as er
|
||||||
from jedi.evaluate import imports
|
from jedi.evaluate import imports
|
||||||
@@ -91,14 +91,14 @@ class Evaluator(object):
|
|||||||
self.analysis = []
|
self.analysis = []
|
||||||
|
|
||||||
def wrap(self, element):
|
def wrap(self, element):
|
||||||
if isinstance(element, pr.Class):
|
if isinstance(element, tree.Class):
|
||||||
return er.Class(self, element)
|
return er.Class(self, element)
|
||||||
elif isinstance(element, pr.Function):
|
elif isinstance(element, tree.Function):
|
||||||
if isinstance(element, pr.Lambda):
|
if isinstance(element, tree.Lambda):
|
||||||
return er.LambdaWrapper(self, element)
|
return er.LambdaWrapper(self, element)
|
||||||
else:
|
else:
|
||||||
return er.Function(self, element)
|
return er.Function(self, element)
|
||||||
elif isinstance(element, (pr.Module)) \
|
elif isinstance(element, (tree.Module)) \
|
||||||
and not isinstance(element, er.ModuleWrapper):
|
and not isinstance(element, er.ModuleWrapper):
|
||||||
return er.ModuleWrapper(self, element)
|
return er.ModuleWrapper(self, element)
|
||||||
else:
|
else:
|
||||||
@@ -130,7 +130,7 @@ class Evaluator(object):
|
|||||||
names are defined in the statement, `seek_name` returns the result for
|
names are defined in the statement, `seek_name` returns the result for
|
||||||
this name.
|
this name.
|
||||||
|
|
||||||
:param stmt: A `pr.ExprStmt`.
|
:param stmt: A `tree.ExprStmt`.
|
||||||
"""
|
"""
|
||||||
debug.dbg('eval_statement %s (%s)', stmt, seek_name)
|
debug.dbg('eval_statement %s (%s)', stmt, seek_name)
|
||||||
types = self.eval_element(stmt.get_rhs())
|
types = self.eval_element(stmt.get_rhs())
|
||||||
@@ -146,7 +146,7 @@ class Evaluator(object):
|
|||||||
name = str(stmt.get_defined_names()[0])
|
name = str(stmt.get_defined_names()[0])
|
||||||
parent = self.wrap(stmt.get_parent_scope())
|
parent = self.wrap(stmt.get_parent_scope())
|
||||||
left = self.find_types(parent, name, stmt.start_pos, search_global=True)
|
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
|
# Iterate through result and add the values, that's possible
|
||||||
# only in for loops without clutter, because they are
|
# only in for loops without clutter, because they are
|
||||||
# predictable.
|
# predictable.
|
||||||
@@ -166,15 +166,15 @@ class Evaluator(object):
|
|||||||
return iterable.unite(self.eval_element(e) for e in element)
|
return iterable.unite(self.eval_element(e) for e in element)
|
||||||
|
|
||||||
debug.dbg('eval_element %s@%s', element, element.start_pos)
|
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)
|
return self._eval_atom(element)
|
||||||
elif isinstance(element, pr.Keyword):
|
elif isinstance(element, tree.Keyword):
|
||||||
# For False/True/None
|
# For False/True/None
|
||||||
if element.value in ('False', 'True', 'None'):
|
if element.value in ('False', 'True', 'None'):
|
||||||
return [compiled.builtin.get_by_name(element.value)]
|
return [compiled.builtin.get_by_name(element.value)]
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
elif element.isinstance(pr.Lambda):
|
elif element.isinstance(tree.Lambda):
|
||||||
return [er.LambdaWrapper(self, element)]
|
return [er.LambdaWrapper(self, element)]
|
||||||
elif element.isinstance(er.LambdaWrapper):
|
elif element.isinstance(er.LambdaWrapper):
|
||||||
return [element] # TODO this is no real evaluation.
|
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
|
generate the node (because it has just one child). In that case an atom
|
||||||
might be a name or a literal as well.
|
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.
|
# This is the first global lookup.
|
||||||
stmt = atom.get_definition()
|
stmt = atom.get_definition()
|
||||||
scope = stmt.get_parent_until(pr.IsScope, include_current=True)
|
scope = stmt.get_parent_until(tree.IsScope, include_current=True)
|
||||||
if isinstance(stmt, pr.CompFor):
|
if isinstance(stmt, tree.CompFor):
|
||||||
stmt = stmt.get_parent_until((pr.ClassOrFunc, pr.ExprStmt))
|
stmt = stmt.get_parent_until((tree.ClassOrFunc, tree.ExprStmt))
|
||||||
if stmt.type != 'expr_stmt':
|
if stmt.type != 'expr_stmt':
|
||||||
# We only need to adjust the start_pos for statements, because
|
# We only need to adjust the start_pos for statements, because
|
||||||
# there the name cannot be used.
|
# there the name cannot be used.
|
||||||
stmt = atom
|
stmt = atom
|
||||||
return self.find_types(scope, atom, stmt.start_pos, search_global=True)
|
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())]
|
return [compiled.create(self, atom.eval())]
|
||||||
else:
|
else:
|
||||||
c = atom.children
|
c = atom.children
|
||||||
# Parentheses without commas are not tuples.
|
# Parentheses without commas are not tuples.
|
||||||
if c[0] == '(' and not len(c) == 2 \
|
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):
|
and len(c[1].children) > 1):
|
||||||
return self.eval_element(c[1])
|
return self.eval_element(c[1])
|
||||||
try:
|
try:
|
||||||
@@ -243,7 +243,7 @@ class Evaluator(object):
|
|||||||
except (IndexError, AttributeError):
|
except (IndexError, AttributeError):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if isinstance(comp_for, pr.CompFor):
|
if isinstance(comp_for, tree.CompFor):
|
||||||
return [iterable.Comprehension.from_atom(self, atom)]
|
return [iterable.Comprehension.from_atom(self, atom)]
|
||||||
return [iterable.Array(self, atom)]
|
return [iterable.Array(self, atom)]
|
||||||
|
|
||||||
@@ -345,13 +345,13 @@ class Evaluator(object):
|
|||||||
param_names += [param.name for param in params
|
param_names += [param.name for param in params
|
||||||
if param.name.value == name.value]
|
if param.name.value == name.value]
|
||||||
return param_names
|
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
|
# Only take the parent, because if it's more complicated than just
|
||||||
# a name it's something you can "goto" again.
|
# a name it's something you can "goto" again.
|
||||||
return [name]
|
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]
|
return [name]
|
||||||
elif isinstance(stmt, pr.Import):
|
elif isinstance(stmt, tree.Import):
|
||||||
modules = imports.ImportWrapper(self, name).follow(is_goto=True)
|
modules = imports.ImportWrapper(self, name).follow(is_goto=True)
|
||||||
return list(resolve_implicit_imports(modules))
|
return list(resolve_implicit_imports(modules))
|
||||||
elif par.type == 'dotted_name': # Is a decorator.
|
elif par.type == 'dotted_name': # Is a decorator.
|
||||||
@@ -365,7 +365,7 @@ class Evaluator(object):
|
|||||||
))
|
))
|
||||||
|
|
||||||
scope = name.get_parent_scope()
|
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)
|
call = helpers.call_of_name(name, cut_own_trailer=True)
|
||||||
types = self.eval_element(call)
|
types = self.eval_element(call)
|
||||||
return resolve_implicit_imports(iterable.unite(
|
return resolve_implicit_imports(iterable.unite(
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
Module for statical analysis.
|
Module for statical analysis.
|
||||||
"""
|
"""
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.parser import tree as pr
|
from jedi.parser import tree
|
||||||
from jedi.evaluate.compiled import CompiledObject
|
from jedi.evaluate.compiled import CompiledObject
|
||||||
|
|
||||||
|
|
||||||
@@ -196,13 +196,13 @@ def _check_for_exception_catch(evaluator, jedi_obj, exception, payload=None):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
obj = jedi_obj
|
obj = jedi_obj
|
||||||
while obj is not None and not obj.isinstance(pr.Function, pr.Class):
|
while obj is not None and not obj.isinstance(tree.Function, tree.Class):
|
||||||
if obj.isinstance(pr.Flow):
|
if obj.isinstance(tree.Flow):
|
||||||
# try/except catch check
|
# 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
|
return True
|
||||||
# hasattr check
|
# 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]):
|
if check_hasattr(obj.children[1], obj.children[3]):
|
||||||
return True
|
return True
|
||||||
obj = obj.parent
|
obj = obj.parent
|
||||||
@@ -243,7 +243,7 @@ def get_module_statements(module):
|
|||||||
def add_nodes(nodes):
|
def add_nodes(nodes):
|
||||||
new = set()
|
new = set()
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
if isinstance(node, pr.Flow):
|
if isinstance(node, tree.Flow):
|
||||||
children = node.children
|
children = node.children
|
||||||
if node.type == 'for_stmt':
|
if node.type == 'for_stmt':
|
||||||
children = children[2:] # Don't want to include the names.
|
children = children[2:] # Don't want to include the names.
|
||||||
@@ -258,7 +258,7 @@ def get_module_statements(module):
|
|||||||
pass
|
pass
|
||||||
elif node.type not in ('whitespace', 'operator', 'keyword',
|
elif node.type not in ('whitespace', 'operator', 'keyword',
|
||||||
'parameters', 'decorated', 'except_clause') \
|
'parameters', 'decorated', 'except_clause') \
|
||||||
and not isinstance(node, (pr.ClassOrFunc, pr.Import)):
|
and not isinstance(node, (tree.ClassOrFunc, tree.Import)):
|
||||||
new.add(node)
|
new.add(node)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -282,7 +282,7 @@ def get_module_statements(module):
|
|||||||
import_names |= set(path[-1] for path in imp.paths())
|
import_names |= set(path[-1] for path in imp.paths())
|
||||||
|
|
||||||
children = scope.children
|
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.
|
children = children[2:] # We don't want to include the class name.
|
||||||
nodes |= add_nodes(children)
|
nodes |= add_nodes(children)
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ It works as follows:
|
|||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from jedi._compatibility import unicode
|
from jedi._compatibility import unicode
|
||||||
from jedi.parser import tree as pr
|
from jedi.parser import tree
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.evaluate.cache import memoize_default
|
from jedi.evaluate.cache import memoize_default
|
||||||
@@ -55,7 +55,7 @@ def search_params(evaluator, param):
|
|||||||
return []
|
return []
|
||||||
debug.dbg('Dynamic param search for %s', param)
|
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.
|
# Compare the param names.
|
||||||
names = [n for n in search_function_call(evaluator, func)
|
names = [n for n in search_function_call(evaluator, func)
|
||||||
if n.value == param.name.value]
|
if n.value == param.name.value]
|
||||||
@@ -85,11 +85,11 @@ def search_function_call(evaluator, func):
|
|||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
parent = name.parent
|
parent = name.parent
|
||||||
if pr.is_node(parent, 'trailer'):
|
if tree.is_node(parent, 'trailer'):
|
||||||
parent = parent.parent
|
parent = parent.parent
|
||||||
|
|
||||||
trailer = None
|
trailer = None
|
||||||
if pr.is_node(parent, 'power'):
|
if tree.is_node(parent, 'power'):
|
||||||
for t in parent.children[1:]:
|
for t in parent.children[1:]:
|
||||||
if t == '**':
|
if t == '**':
|
||||||
break
|
break
|
||||||
@@ -124,7 +124,7 @@ def search_function_call(evaluator, func):
|
|||||||
compare = func
|
compare = func
|
||||||
if func_name == '__init__':
|
if func_name == '__init__':
|
||||||
cls = func.get_parent_scope()
|
cls = func.get_parent_scope()
|
||||||
if isinstance(cls, pr.Class):
|
if isinstance(cls, tree.Class):
|
||||||
func_name = unicode(cls.name)
|
func_name = unicode(cls.name)
|
||||||
compare = cls
|
compare = cls
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ check for -> a is a string). There's big potential in these checks.
|
|||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from jedi._compatibility import unicode, u
|
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 debug
|
||||||
from jedi import common
|
from jedi import common
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
@@ -43,7 +43,7 @@ def filter_after_position(names, position):
|
|||||||
for n in names:
|
for n in names:
|
||||||
# Filter positions and also allow list comprehensions and lambdas.
|
# Filter positions and also allow list comprehensions and lambdas.
|
||||||
if n.start_pos[0] is not None and n.start_pos < position \
|
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)
|
names_new.append(n)
|
||||||
return names_new
|
return names_new
|
||||||
|
|
||||||
@@ -87,8 +87,8 @@ class NameFinder(object):
|
|||||||
types = self._names_to_types(names, search_global)
|
types = self._names_to_types(names, search_global)
|
||||||
|
|
||||||
if not names and not types \
|
if not names and not types \
|
||||||
and not (isinstance(self.name_str, pr.Name)
|
and not (isinstance(self.name_str, tree.Name)
|
||||||
and isinstance(self.name_str.parent.parent, pr.Param)):
|
and isinstance(self.name_str.parent.parent, tree.Param)):
|
||||||
if not isinstance(self.name_str, (str, unicode)): # TODO Remove?
|
if not isinstance(self.name_str, (str, unicode)): # TODO Remove?
|
||||||
if search_global:
|
if search_global:
|
||||||
message = ("NameError: name '%s' is not defined."
|
message = ("NameError: name '%s' is not defined."
|
||||||
@@ -110,7 +110,7 @@ class NameFinder(object):
|
|||||||
|
|
||||||
def names_dict_lookup(self, names_dict, position):
|
def names_dict_lookup(self, names_dict, position):
|
||||||
def get_param(scope, el):
|
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 scope.param_by_name(str(el))
|
||||||
return el
|
return el
|
||||||
|
|
||||||
@@ -148,8 +148,8 @@ class NameFinder(object):
|
|||||||
last_names.append(name)
|
last_names.append(name)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if isinstance(self.name_str, pr.Name):
|
if isinstance(self.name_str, tree.Name):
|
||||||
origin_scope = self.name_str.get_parent_until(pr.Scope, reverse=True)
|
origin_scope = self.name_str.get_parent_until(tree.Scope, reverse=True)
|
||||||
else:
|
else:
|
||||||
origin_scope = None
|
origin_scope = None
|
||||||
if isinstance(stmt.parent, compiled.CompiledObject):
|
if isinstance(stmt.parent, compiled.CompiledObject):
|
||||||
@@ -190,7 +190,7 @@ class NameFinder(object):
|
|||||||
"""
|
"""
|
||||||
for n in names:
|
for n in names:
|
||||||
definition = n.parent
|
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
|
yield self._evaluator.wrap(definition).name
|
||||||
else:
|
else:
|
||||||
yield n
|
yield n
|
||||||
@@ -215,7 +215,7 @@ class NameFinder(object):
|
|||||||
types = []
|
types = []
|
||||||
|
|
||||||
# Add isinstance and other if/assert knowledge.
|
# 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.
|
# Ignore FunctionExecution parents for now.
|
||||||
flow_scope = self.name_str
|
flow_scope = self.name_str
|
||||||
until = flow_scope.get_parent_until(er.FunctionExecution)
|
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
|
# definition. __get__ is only called if the descriptor is defined in
|
||||||
# the class dictionary.
|
# the class dictionary.
|
||||||
name_scope = name.get_definition().get_parent_scope()
|
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
|
return types
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
@@ -264,23 +264,23 @@ class NameFinder(object):
|
|||||||
def _name_to_types(evaluator, name, scope):
|
def _name_to_types(evaluator, name, scope):
|
||||||
types = []
|
types = []
|
||||||
typ = name.get_definition()
|
typ = name.get_definition()
|
||||||
if typ.isinstance(pr.ForStmt):
|
if typ.isinstance(tree.ForStmt):
|
||||||
for_types = evaluator.eval_element(typ.children[3])
|
for_types = evaluator.eval_element(typ.children[3])
|
||||||
for_types = iterable.get_iterator_types(for_types)
|
for_types = iterable.get_iterator_types(for_types)
|
||||||
types += check_tuple_assignments(for_types, name)
|
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 = evaluator.eval_element(typ.children[3])
|
||||||
for_types = iterable.get_iterator_types(for_types)
|
for_types = iterable.get_iterator_types(for_types)
|
||||||
types += check_tuple_assignments(for_types, name)
|
types += check_tuple_assignments(for_types, name)
|
||||||
elif isinstance(typ, pr.Param):
|
elif isinstance(typ, tree.Param):
|
||||||
types += _eval_param(evaluator, typ, scope)
|
types += _eval_param(evaluator, typ, scope)
|
||||||
elif typ.isinstance(pr.ExprStmt):
|
elif typ.isinstance(tree.ExprStmt):
|
||||||
types += _remove_statements(evaluator, typ, name)
|
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))
|
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()
|
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
|
# TODO theoretically we shouldn't be using search_global here, it
|
||||||
# doesn't make sense, because it's a local search (for that name)!
|
# doesn't make sense, because it's a local search (for that name)!
|
||||||
# However, globals are not that important and resolving them doesn't
|
# 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.
|
# something is executed.
|
||||||
types += evaluator.find_types(typ.get_parent_scope(), str(name),
|
types += evaluator.find_types(typ.get_parent_scope(), str(name),
|
||||||
search_global=True)
|
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 an exception can also be a tuple. Check for those.
|
||||||
# TODO check for types that are not classes and add it to
|
# TODO check for types that are not classes and add it to
|
||||||
# the static analysis report.
|
# the static analysis report.
|
||||||
@@ -325,7 +325,7 @@ def _remove_statements(evaluator, stmt, name):
|
|||||||
if check_instance is not None:
|
if check_instance is not None:
|
||||||
# class renames
|
# class renames
|
||||||
types = [er.get_instance_el(evaluator, check_instance, a, True)
|
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]
|
else a for a in types]
|
||||||
return types
|
return types
|
||||||
|
|
||||||
@@ -334,10 +334,10 @@ def _eval_param(evaluator, param, scope):
|
|||||||
res_new = []
|
res_new = []
|
||||||
func = param.get_parent_scope()
|
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
|
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):
|
and not isinstance(param, ExecutedParam):
|
||||||
# This is where we add self - if it has never been
|
# This is where we add self - if it has never been
|
||||||
# instantiated.
|
# instantiated.
|
||||||
@@ -396,13 +396,13 @@ def check_flow_information(evaluator, flow, search_name, pos):
|
|||||||
names = []
|
names = []
|
||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
ass = name.get_parent_until(pr.AssertStmt)
|
ass = name.get_parent_until(tree.AssertStmt)
|
||||||
if isinstance(ass, pr.AssertStmt) and pos is not None and ass.start_pos < pos:
|
if isinstance(ass, tree.AssertStmt) and pos is not None and ass.start_pos < pos:
|
||||||
result = _check_isinstance_type(evaluator, ass.assertion(), search_name)
|
result = _check_isinstance_type(evaluator, ass.assertion(), search_name)
|
||||||
if result:
|
if result:
|
||||||
break
|
break
|
||||||
|
|
||||||
if isinstance(flow, (pr.IfStmt, pr.WhileStmt)):
|
if isinstance(flow, (tree.IfStmt, tree.WhileStmt)):
|
||||||
element = flow.children[1]
|
element = flow.children[1]
|
||||||
result = _check_isinstance_type(evaluator, element, search_name)
|
result = _check_isinstance_type(evaluator, element, search_name)
|
||||||
return result
|
return result
|
||||||
@@ -414,7 +414,7 @@ def _check_isinstance_type(evaluator, element, search_name):
|
|||||||
# this might be removed if we analyze and, etc
|
# this might be removed if we analyze and, etc
|
||||||
assert len(element.children) == 2
|
assert len(element.children) == 2
|
||||||
first, trailer = element.children
|
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 trailer.type == 'trailer' and trailer.children[0] == '('
|
||||||
assert len(trailer.children) == 3
|
assert len(trailer.children) == 3
|
||||||
|
|
||||||
@@ -536,7 +536,7 @@ def filter_private_variable(scope, origin_node):
|
|||||||
instance = scope.get_parent_scope()
|
instance = scope.get_parent_scope()
|
||||||
coming_from = origin_node
|
coming_from = origin_node
|
||||||
while coming_from is not None \
|
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()
|
coming_from = coming_from.get_parent_scope()
|
||||||
|
|
||||||
# CompiledObjects don't have double underscore attributes, but Jedi abuses
|
# CompiledObjects don't have double underscore attributes, but Jedi abuses
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from jedi.parser import tree as pr
|
from jedi.parser import tree
|
||||||
|
|
||||||
|
|
||||||
class Status(object):
|
class Status(object):
|
||||||
@@ -53,7 +53,7 @@ def _break_check(evaluator, stmt, base_scope, element_scope):
|
|||||||
base_scope = evaluator.wrap(base_scope)
|
base_scope = evaluator.wrap(base_scope)
|
||||||
|
|
||||||
reachable = REACHABLE
|
reachable = REACHABLE
|
||||||
if isinstance(element_scope, pr.IfStmt):
|
if isinstance(element_scope, tree.IfStmt):
|
||||||
if element_scope.node_after_else(stmt):
|
if element_scope.node_after_else(stmt):
|
||||||
for check_node in element_scope.check_nodes():
|
for check_node in element_scope.check_nodes():
|
||||||
reachable = _check_if(evaluator, check_node)
|
reachable = _check_if(evaluator, check_node)
|
||||||
@@ -63,7 +63,7 @@ def _break_check(evaluator, stmt, base_scope, element_scope):
|
|||||||
else:
|
else:
|
||||||
node = element_scope.node_in_which_check_node(stmt)
|
node = element_scope.node_in_which_check_node(stmt)
|
||||||
reachable = _check_if(evaluator, node)
|
reachable = _check_if(evaluator, node)
|
||||||
elif isinstance(element_scope, (pr.TryStmt, pr.WhileStmt)):
|
elif isinstance(element_scope, (tree.TryStmt, tree.WhileStmt)):
|
||||||
return UNSURE
|
return UNSURE
|
||||||
|
|
||||||
# Only reachable branches need to be examined further.
|
# Only reachable branches need to be examined further.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import copy
|
import copy
|
||||||
from itertools import chain
|
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):
|
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)
|
new_elements[obj] = new_obj = copy.copy(obj)
|
||||||
if parent is not None:
|
if parent is not None:
|
||||||
new_obj.parent = parent
|
new_obj.parent = parent
|
||||||
elif isinstance(obj, pr.BaseNode):
|
elif isinstance(obj, tree.BaseNode):
|
||||||
new_obj = copy_node(obj)
|
new_obj = copy_node(obj)
|
||||||
if parent is not None:
|
if parent is not None:
|
||||||
for child in new_obj.children:
|
for child in new_obj.children:
|
||||||
if isinstance(child, (pr.Name, pr.BaseNode)):
|
if isinstance(child, (tree.Name, tree.BaseNode)):
|
||||||
child.parent = parent
|
child.parent = parent
|
||||||
else: # String literals and so on.
|
else: # String literals and so on.
|
||||||
new_obj = obj # Good enough, don't need to copy anything.
|
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.
|
This generates a copy of the original ast node.
|
||||||
"""
|
"""
|
||||||
par = name
|
par = name
|
||||||
if pr.is_node(par.parent, 'trailer'):
|
if tree.is_node(par.parent, 'trailer'):
|
||||||
par = par.parent
|
par = par.parent
|
||||||
|
|
||||||
power = 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
|
and not (power.children[-2] == '**' and
|
||||||
name.start_pos > power.children[-1].start_pos):
|
name.start_pos > power.children[-1].start_pos):
|
||||||
par = power
|
par = power
|
||||||
@@ -117,7 +117,7 @@ def get_module_names(module, all_scopes):
|
|||||||
return chain.from_iterable(dct.values())
|
return chain.from_iterable(dct.values())
|
||||||
|
|
||||||
|
|
||||||
class FakeImport(pr.ImportName):
|
class FakeImport(tree.ImportName):
|
||||||
def __init__(self, name, parent, level=0):
|
def __init__(self, name, parent, level=0):
|
||||||
super(FakeImport, self).__init__([])
|
super(FakeImport, self).__init__([])
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
@@ -145,13 +145,13 @@ class FakeImport(pr.ImportName):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class FakeName(pr.Name):
|
class FakeName(tree.Name):
|
||||||
def __init__(self, name_str, parent=None, start_pos=(0, 0), is_definition=None):
|
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
|
In case is_definition is defined (not None), that bool value will be
|
||||||
returned.
|
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.parent = parent
|
||||||
self._is_definition = is_definition
|
self._is_definition = is_definition
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from jedi import common
|
|||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import cache
|
from jedi import cache
|
||||||
from jedi.parser import fast
|
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 sys_path
|
||||||
from jedi.evaluate import helpers
|
from jedi.evaluate import helpers
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
@@ -50,7 +50,7 @@ def completion_names(evaluator, imp, pos):
|
|||||||
level = imp.level
|
level = imp.level
|
||||||
|
|
||||||
importer = get_importer(evaluator, tuple(import_path), module, level)
|
importer = get_importer(evaluator, tuple(import_path), module, level)
|
||||||
if isinstance(imp, pr.ImportFrom):
|
if isinstance(imp, tree.ImportFrom):
|
||||||
c = imp.children
|
c = imp.children
|
||||||
only_modules = c[c.index('import')].start_pos >= pos
|
only_modules = c[c.index('import')].start_pos >= pos
|
||||||
else:
|
else:
|
||||||
@@ -58,12 +58,12 @@ def completion_names(evaluator, imp, pos):
|
|||||||
return importer.completion_names(evaluator, only_modules)
|
return importer.completion_names(evaluator, only_modules)
|
||||||
|
|
||||||
|
|
||||||
class ImportWrapper(pr.Base):
|
class ImportWrapper(tree.Base):
|
||||||
def __init__(self, evaluator, name):
|
def __init__(self, evaluator, name):
|
||||||
self._evaluator = evaluator
|
self._evaluator = evaluator
|
||||||
self._name = name
|
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)
|
self.import_path = self._import.path_for_name(name)
|
||||||
|
|
||||||
@memoize_default()
|
@memoize_default()
|
||||||
@@ -138,7 +138,7 @@ class ImportWrapper(pr.Base):
|
|||||||
return types
|
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
|
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.
|
be able to use them for static analysis checks later on.
|
||||||
@@ -157,7 +157,7 @@ class NestedImportModule(pr.Module):
|
|||||||
zero = (0, 0)
|
zero = (0, 0)
|
||||||
names = [unicode(name) for name in i.namespace_names[1:]]
|
names = [unicode(name) for name in i.namespace_names[1:]]
|
||||||
name = helpers.FakeName(names, self._nested_import)
|
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
|
new.parent = self._module
|
||||||
debug.dbg('Generated a nested import: %s', new)
|
debug.dbg('Generated a nested import: %s', new)
|
||||||
return helpers.FakeName(str(i.namespace_names[1]), new)
|
return helpers.FakeName(str(i.namespace_names[1]), new)
|
||||||
@@ -462,7 +462,7 @@ class _Importer(object):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# namespace packages
|
# 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)
|
pkg_path = os.path.dirname(scope.path)
|
||||||
paths = self.namespace_packages(pkg_path, self.import_path)
|
paths = self.namespace_packages(pkg_path, self.import_path)
|
||||||
names += self._get_module_names([pkg_path] + paths)
|
names += self._get_module_names([pkg_path] + paths)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ from jedi import common
|
|||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi._compatibility import use_metaclass, is_py3, unicode
|
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 compiled
|
||||||
from jedi.evaluate import helpers
|
from jedi.evaluate import helpers
|
||||||
from jedi.evaluate.cache import CachedMetaClass, memoize_default
|
from jedi.evaluate.cache import CachedMetaClass, memoize_default
|
||||||
@@ -38,7 +38,7 @@ def unite(iterable):
|
|||||||
return list(chain.from_iterable(iterable))
|
return list(chain.from_iterable(iterable))
|
||||||
|
|
||||||
|
|
||||||
class IterableWrapper(pr.Base):
|
class IterableWrapper(tree.Base):
|
||||||
def is_class(self):
|
def is_class(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -140,9 +140,9 @@ class Comprehension(IterableWrapper):
|
|||||||
last = comprehension.children[-1]
|
last = comprehension.children[-1]
|
||||||
last_comp = comprehension.children[1]
|
last_comp = comprehension.children[1]
|
||||||
while True:
|
while True:
|
||||||
if isinstance(last, pr.CompFor):
|
if isinstance(last, tree.CompFor):
|
||||||
last_comp = last
|
last_comp = last
|
||||||
elif not pr.is_node(last, 'comp_if'):
|
elif not tree.is_node(last, 'comp_if'):
|
||||||
break
|
break
|
||||||
last = last.children[-1]
|
last = last.children[-1]
|
||||||
|
|
||||||
@@ -283,9 +283,9 @@ class Array(IterableWrapper, ArrayMixin):
|
|||||||
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 pr.is_node(array_node, 'testlist_comp'):
|
if tree.is_node(array_node, 'testlist_comp'):
|
||||||
return array_node.children[::2]
|
return array_node.children[::2]
|
||||||
elif pr.is_node(array_node, 'dictorsetmaker'):
|
elif tree.is_node(array_node, 'dictorsetmaker'):
|
||||||
kv = []
|
kv = []
|
||||||
iterator = iter(array_node.children)
|
iterator = iter(array_node.children)
|
||||||
for key in iterator:
|
for key in iterator:
|
||||||
@@ -613,14 +613,14 @@ class Slice(object):
|
|||||||
|
|
||||||
|
|
||||||
def create_indexes_or_slices(evaluator, index):
|
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
|
start, stop, step = None, None, None
|
||||||
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 pr.is_node(el, 'sliceop'):
|
elif tree.is_node(el, 'sliceop'):
|
||||||
if len(el.children) == 2:
|
if len(el.children) == 2:
|
||||||
result.append(el.children[1])
|
result.append(el.children[1])
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from itertools import chain
|
|||||||
from jedi._compatibility import unicode, zip_longest
|
from jedi._compatibility import unicode, zip_longest
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import common
|
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 iterable
|
||||||
from jedi.evaluate import analysis
|
from jedi.evaluate import analysis
|
||||||
from jedi.evaluate import precedence
|
from jedi.evaluate import precedence
|
||||||
@@ -12,7 +12,7 @@ from jedi.evaluate.helpers import FakeName
|
|||||||
from jedi.cache import underscore_memoization
|
from jedi.cache import underscore_memoization
|
||||||
|
|
||||||
|
|
||||||
class Arguments(pr.Base):
|
class Arguments(tree.Base):
|
||||||
def __init__(self, evaluator, argument_node, trailer=None):
|
def __init__(self, evaluator, argument_node, trailer=None):
|
||||||
"""
|
"""
|
||||||
The argument_node is either a parser node or a list of evaluated
|
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:
|
for el in self.argument_node:
|
||||||
yield 0, el
|
yield 0, el
|
||||||
else:
|
else:
|
||||||
if not pr.is_node(self.argument_node, 'arglist'):
|
if not tree.is_node(self.argument_node, 'arglist'):
|
||||||
yield 0, self.argument_node
|
yield 0, self.argument_node
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ class Arguments(pr.Base):
|
|||||||
|
|
||||||
def as_tuple(self):
|
def as_tuple(self):
|
||||||
for stars, argument in self._split():
|
for stars, argument in self._split():
|
||||||
if pr.is_node(argument, 'argument'):
|
if tree.is_node(argument, 'argument'):
|
||||||
argument, default = argument.children[::2]
|
argument, default = argument.children[::2]
|
||||||
else:
|
else:
|
||||||
default = None
|
default = None
|
||||||
@@ -83,7 +83,7 @@ class Arguments(pr.Base):
|
|||||||
for key, values in dct.items():
|
for key, values in dct.items():
|
||||||
yield key, values
|
yield key, values
|
||||||
else:
|
else:
|
||||||
if pr.is_node(el, 'argument'):
|
if tree.is_node(el, '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, (c[2],)))
|
named_args.append((c[0].value, (c[2],)))
|
||||||
@@ -106,7 +106,7 @@ class Arguments(pr.Base):
|
|||||||
named_index = None
|
named_index = None
|
||||||
new_args = []
|
new_args = []
|
||||||
for i, stmt in enumerate(var_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:
|
if named_index is None and stmt.assignment_details:
|
||||||
named_index = i
|
named_index = i
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ class Arguments(pr.Base):
|
|||||||
|
|
||||||
def scope(self):
|
def scope(self):
|
||||||
# Returns the scope in which the arguments are used.
|
# 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):
|
def eval_args(self):
|
||||||
# TODO this method doesn't work with named args and a lot of other
|
# 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)
|
return '<%s: %s>' % (type(self).__name__, self.argument_node)
|
||||||
|
|
||||||
def get_calling_var_args(self):
|
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:
|
or self.argument_node == () and self.trailer is not None:
|
||||||
return _get_calling_var_args(self._evaluator, self)
|
return _get_calling_var_args(self._evaluator, self)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class ExecutedParam(pr.Param):
|
class ExecutedParam(tree.Param):
|
||||||
"""Fake a param and give it values."""
|
"""Fake a param and give it values."""
|
||||||
def __init__(self, original_param, var_args, values):
|
def __init__(self, original_param, var_args, values):
|
||||||
self._original_param = original_param
|
self._original_param = original_param
|
||||||
@@ -193,7 +193,7 @@ def _get_calling_var_args(evaluator, var_args):
|
|||||||
while var_args != old_var_args:
|
while var_args != old_var_args:
|
||||||
old_var_args = var_args
|
old_var_args = var_args
|
||||||
for name, default, stars in reversed(list(var_args.as_tuple())):
|
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
|
continue
|
||||||
|
|
||||||
names = evaluator.goto(name)
|
names = evaluator.goto(name)
|
||||||
@@ -201,7 +201,7 @@ def _get_calling_var_args(evaluator, var_args):
|
|||||||
break
|
break
|
||||||
param = names[0].get_definition()
|
param = names[0].get_definition()
|
||||||
if not isinstance(param, ExecutedParam):
|
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
|
# There is no calling var_args in this case - there's just
|
||||||
# a param without any input.
|
# a param without any input.
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Handles operator precedence.
|
|||||||
import operator
|
import operator
|
||||||
|
|
||||||
from jedi._compatibility import unicode
|
from jedi._compatibility import unicode
|
||||||
from jedi.parser import tree as pr
|
from jedi.parser import tree
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.evaluate.compiled import (CompiledObject, create, builtin,
|
from jedi.evaluate.compiled import (CompiledObject, create, builtin,
|
||||||
keyword_from_value, true_obj, false_obj)
|
keyword_from_value, true_obj, false_obj)
|
||||||
@@ -43,7 +43,7 @@ def calculate_children(evaluator, children):
|
|||||||
types = evaluator.eval_element(next(iterator))
|
types = evaluator.eval_element(next(iterator))
|
||||||
for operator in iterator:
|
for operator in iterator:
|
||||||
right = next(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)
|
operator = ' '.join(str(c.value) for c in operator.children)
|
||||||
|
|
||||||
# handle lazy evaluation of and/or here.
|
# handle lazy evaluation of and/or here.
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import re
|
|||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from jedi._compatibility import use_metaclass, unicode, Python3Method
|
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 debug
|
||||||
from jedi import common
|
from jedi import common
|
||||||
from jedi.cache import underscore_memoization, cache_star_import
|
from jedi.cache import underscore_memoization, cache_star_import
|
||||||
@@ -50,7 +50,7 @@ from jedi.evaluate import flow_analysis
|
|||||||
from jedi.evaluate import imports
|
from jedi.evaluate import imports
|
||||||
|
|
||||||
|
|
||||||
class Executed(pr.Base):
|
class Executed(tree.Base):
|
||||||
"""
|
"""
|
||||||
An instance is also an executable - because __init__ is called
|
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.
|
: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
|
return True
|
||||||
|
|
||||||
def get_parent_until(self, *args, **kwargs):
|
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
|
@common.safe_property
|
||||||
def parent(self):
|
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
|
# This loop adds the names of the self object, copies them and removes
|
||||||
# the self.
|
# the self.
|
||||||
for sub in self.base.subscopes:
|
for sub in self.base.subscopes:
|
||||||
if isinstance(sub, pr.Class):
|
if isinstance(sub, tree.Class):
|
||||||
continue
|
continue
|
||||||
# Get the self name, if there's one.
|
# Get the self name, if there's one.
|
||||||
self_name = self._get_func_self_name(sub)
|
self_name = self._get_func_self_name(sub)
|
||||||
@@ -155,7 +155,7 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
|
|||||||
for name in name_list:
|
for name in name_list:
|
||||||
if name.value == self_name and name.prev_sibling() is None:
|
if name.value == self_name and name.prev_sibling() is None:
|
||||||
trailer = name.next_sibling()
|
trailer = name.next_sibling()
|
||||||
if pr.is_node(trailer, 'trailer') \
|
if tree.is_node(trailer, 'trailer') \
|
||||||
and len(trailer.children) == 2 \
|
and len(trailer.children) == 2 \
|
||||||
and trailer.children[0] == '.':
|
and trailer.children[0] == '.':
|
||||||
name = trailer.children[1] # After dot.
|
name = trailer.children[1] # After dot.
|
||||||
@@ -246,9 +246,9 @@ class LazyInstanceDict(object):
|
|||||||
return [self[key] for key in self._dct]
|
return [self[key] for key in self._dct]
|
||||||
|
|
||||||
|
|
||||||
class InstanceName(pr.Name):
|
class InstanceName(tree.Name):
|
||||||
def __init__(self, origin_name, parent):
|
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.value,
|
||||||
origin_name.start_pos)
|
origin_name.start_pos)
|
||||||
self._origin_name = origin_name
|
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
|
in quite a lot of cases, which includes Nodes like ``power``, that need to
|
||||||
know where a self name comes from for example.
|
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)
|
parent = get_instance_el(evaluator, instance, var.parent, is_class_var)
|
||||||
return InstanceName(var, parent)
|
return InstanceName(var, parent)
|
||||||
elif var.type != 'funcdef' \
|
elif var.type != 'funcdef' \
|
||||||
and isinstance(var, (Instance, compiled.CompiledObject, pr.Leaf,
|
and isinstance(var, (Instance, compiled.CompiledObject, tree.Leaf,
|
||||||
pr.Module, FunctionExecution)):
|
tree.Module, FunctionExecution)):
|
||||||
return var
|
return var
|
||||||
|
|
||||||
var = evaluator.wrap(var)
|
var = evaluator.wrap(var)
|
||||||
return InstanceElement(evaluator, instance, var, is_class_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
|
InstanceElement is a wrapper for any object, that is used as an instance
|
||||||
variable (e.g. self.variable or class methods).
|
variable (e.g. self.variable or class methods).
|
||||||
@@ -295,7 +295,7 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
def parent(self):
|
def parent(self):
|
||||||
par = self.var.parent
|
par = self.var.parent
|
||||||
if isinstance(par, Class) and par == self.instance.base \
|
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:
|
and par == self.instance.base.base:
|
||||||
par = self.instance
|
par = self.instance
|
||||||
else:
|
else:
|
||||||
@@ -304,10 +304,10 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
return par
|
return par
|
||||||
|
|
||||||
def get_parent_until(self, *args, **kwargs):
|
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):
|
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):
|
def get_decorated_func(self):
|
||||||
""" Needed because the InstanceElement should not be stripped """
|
""" 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)
|
return "<%s of %s>" % (type(self).__name__, self.var)
|
||||||
|
|
||||||
|
|
||||||
class Wrapper(pr.Base):
|
class Wrapper(tree.Base):
|
||||||
def is_scope(self):
|
def is_scope(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -383,7 +383,7 @@ class Wrapper(pr.Base):
|
|||||||
|
|
||||||
class Class(use_metaclass(CachedMetaClass, Wrapper)):
|
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).
|
important for descriptors (if the descriptor methods are evaluated or not).
|
||||||
"""
|
"""
|
||||||
def __init__(self, evaluator, base):
|
def __init__(self, evaluator, base):
|
||||||
@@ -505,7 +505,7 @@ class Function(use_metaclass(CachedMetaClass, Wrapper)):
|
|||||||
trailer = dec.children[2:-1]
|
trailer = dec.children[2:-1]
|
||||||
if trailer:
|
if trailer:
|
||||||
# Create a trailer and evaluate it.
|
# 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)
|
dec_results = self._evaluator.eval_trailer(dec_results, trailer)
|
||||||
|
|
||||||
if not len(dec_results):
|
if not len(dec_results):
|
||||||
@@ -629,7 +629,7 @@ class FunctionExecution(Executed):
|
|||||||
def _get_params(self):
|
def _get_params(self):
|
||||||
"""
|
"""
|
||||||
This returns the params for an TODO and is injected as a
|
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,
|
This needs to be here, because Instance can have __init__ functions,
|
||||||
which act the same way as normal 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]
|
return [n for n in self._get_params() if str(n) == name][0]
|
||||||
|
|
||||||
def name_for_position(self, position):
|
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):
|
def _copy_list(self, lst):
|
||||||
"""
|
"""
|
||||||
@@ -671,22 +671,22 @@ class FunctionExecution(Executed):
|
|||||||
@common.safe_property
|
@common.safe_property
|
||||||
@memoize_default([])
|
@memoize_default([])
|
||||||
def returns(self):
|
def returns(self):
|
||||||
return pr.Scope._search_in_scope(self, pr.ReturnStmt)
|
return tree.Scope._search_in_scope(self, tree.ReturnStmt)
|
||||||
|
|
||||||
@common.safe_property
|
@common.safe_property
|
||||||
@memoize_default([])
|
@memoize_default([])
|
||||||
def yields(self):
|
def yields(self):
|
||||||
return pr.Scope._search_in_scope(self, pr.YieldExpr)
|
return tree.Scope._search_in_scope(self, tree.YieldExpr)
|
||||||
|
|
||||||
@common.safe_property
|
@common.safe_property
|
||||||
@memoize_default([])
|
@memoize_default([])
|
||||||
def statements(self):
|
def statements(self):
|
||||||
return pr.Scope._search_in_scope(self, pr.ExprStmt)
|
return tree.Scope._search_in_scope(self, tree.ExprStmt)
|
||||||
|
|
||||||
@common.safe_property
|
@common.safe_property
|
||||||
@memoize_default([])
|
@memoize_default([])
|
||||||
def subscopes(self):
|
def subscopes(self):
|
||||||
return pr.Scope._search_in_scope(self, pr.Scope)
|
return tree.Scope._search_in_scope(self, tree.Scope)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s of %s>" % (type(self).__name__, self.base)
|
return "<%s of %s>" % (type(self).__name__, self.base)
|
||||||
@@ -702,7 +702,7 @@ class GlobalName(helpers.FakeName):
|
|||||||
name.start_pos, is_definition=True)
|
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):
|
def __init__(self, evaluator, module):
|
||||||
self._evaluator = evaluator
|
self._evaluator = evaluator
|
||||||
self.base = self._module = module
|
self.base = self._module = module
|
||||||
@@ -729,7 +729,7 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
|
|||||||
name = i.star_import_name()
|
name = i.star_import_name()
|
||||||
new = imports.ImportWrapper(self._evaluator, name).follow()
|
new = imports.ImportWrapper(self._evaluator, name).follow()
|
||||||
for module in new:
|
for module in new:
|
||||||
if isinstance(module, pr.Module):
|
if isinstance(module, tree.Module):
|
||||||
modules += module.star_imports()
|
modules += module.star_imports()
|
||||||
modules += new
|
modules += new
|
||||||
return modules
|
return modules
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from jedi.evaluate import compiled
|
|||||||
from jedi.evaluate import representation as er
|
from jedi.evaluate import representation as er
|
||||||
from jedi.evaluate import iterable
|
from jedi.evaluate import iterable
|
||||||
from jedi.parser import Parser
|
from jedi.parser import Parser
|
||||||
from jedi.parser import tree as pr
|
from jedi.parser import tree
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.evaluate import precedence
|
from jedi.evaluate import precedence
|
||||||
from jedi.evaluate import param
|
from jedi.evaluate import param
|
||||||
@@ -32,7 +32,7 @@ def execute(evaluator, obj, params):
|
|||||||
else:
|
else:
|
||||||
if obj.parent == compiled.builtin:
|
if obj.parent == compiled.builtin:
|
||||||
module_name = 'builtins'
|
module_name = 'builtins'
|
||||||
elif isinstance(obj.parent, pr.Module):
|
elif isinstance(obj.parent, tree.Module):
|
||||||
module_name = str(obj.parent.name)
|
module_name = str(obj.parent.name)
|
||||||
else:
|
else:
|
||||||
module_name = ''
|
module_name = ''
|
||||||
@@ -98,7 +98,7 @@ def builtins_getattr(evaluator, objects, names, defaults=None):
|
|||||||
types = []
|
types = []
|
||||||
# follow the first param
|
# follow the first param
|
||||||
for obj in objects:
|
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')
|
debug.warning('getattr called without instance')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -130,13 +130,13 @@ class SuperInstance(er.Instance):
|
|||||||
@argument_clinic('[type[, obj]], /', want_scope=True)
|
@argument_clinic('[type[, obj]], /', want_scope=True)
|
||||||
def builtins_super(evaluator, types, objects, scope):
|
def builtins_super(evaluator, types, objects, scope):
|
||||||
# TODO make this able to detect multiple inheritance super
|
# TODO make this able to detect multiple inheritance super
|
||||||
accept = (pr.Function, er.FunctionExecution)
|
accept = (tree.Function, er.FunctionExecution)
|
||||||
if scope.isinstance(*accept):
|
if scope.isinstance(*accept):
|
||||||
wanted = (pr.Class, er.Instance)
|
wanted = (tree.Class, er.Instance)
|
||||||
cls = scope.get_parent_until(accept + wanted,
|
cls = scope.get_parent_until(accept + wanted,
|
||||||
include_current=False)
|
include_current=False)
|
||||||
if isinstance(cls, wanted):
|
if isinstance(cls, wanted):
|
||||||
if isinstance(cls, pr.Class):
|
if isinstance(cls, tree.Class):
|
||||||
cls = er.Class(evaluator, cls)
|
cls = er.Class(evaluator, cls)
|
||||||
elif isinstance(cls, er.Instance):
|
elif isinstance(cls, er.Instance):
|
||||||
cls = cls.base
|
cls = cls.base
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from jedi._compatibility import exec_function, unicode
|
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.parser import Parser
|
||||||
from jedi.evaluate.cache import memoize_default
|
from jedi.evaluate.cache import memoize_default
|
||||||
from jedi import debug
|
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]):
|
for assignee, operator in zip(expr_stmt.children[::2], expr_stmt.children[1::2]):
|
||||||
try:
|
try:
|
||||||
assert operator in ['=', '+=']
|
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
|
c = assignee.children
|
||||||
assert c[0].type == 'name' and c[0].value == 'sys'
|
assert c[0].type == 'name' and c[0].value == 'sys'
|
||||||
trailer = c[1]
|
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" """
|
""" 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 (pr.is_node(trailer1, 'trailer') and trailer1.children[0] == '.'
|
if not (tree.is_node(trailer1, 'trailer') and trailer1.children[0] == '.'
|
||||||
and pr.is_node(trailer2, 'trailer') and trailer2.children[0] == '('
|
and tree.is_node(trailer2, 'trailer') and trailer2.children[0] == '('
|
||||||
and len(trailer2.children) == 3):
|
and len(trailer2.children) == 3):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -120,12 +120,12 @@ def _check_module(evaluator, module):
|
|||||||
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 pr.is_node(power, 'power'):
|
if tree.is_node(power, 'power'):
|
||||||
c = power.children
|
c = power.children
|
||||||
if isinstance(c[0], pr.Name) and c[0].value == 'sys' \
|
if isinstance(c[0], tree.Name) and c[0].value == 'sys' \
|
||||||
and pr.is_node(c[1], 'trailer'):
|
and tree.is_node(c[1], 'trailer'):
|
||||||
n = c[1].children[1]
|
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
|
yield name, power
|
||||||
|
|
||||||
sys_path = list(get_sys_path()) # copy
|
sys_path = list(get_sys_path()) # copy
|
||||||
|
|||||||
Reference in New Issue
Block a user