forked from VimPlug/jedi
PyObject -> CompiledObject, PyName -> CompiledName
This commit is contained in:
@@ -143,7 +143,7 @@ class Script(object):
|
|||||||
if not dot:
|
if not dot:
|
||||||
# add named params
|
# add named params
|
||||||
for call_def in self.call_signatures():
|
for call_def in self.call_signatures():
|
||||||
if not isinstance(call_def.module, compiled.PyObject):
|
if not isinstance(call_def.module, compiled.CompiledObject):
|
||||||
for p in call_def.params:
|
for p in call_def.params:
|
||||||
completions.append((p.get_name(), p))
|
completions.append((p.get_name(), p))
|
||||||
|
|
||||||
@@ -519,7 +519,7 @@ class Script(object):
|
|||||||
|
|
||||||
return [classes.CallDef(o, index, call) for o in origins
|
return [classes.CallDef(o, index, call) for o in origins
|
||||||
if o.isinstance(er.Function, er.Instance, er.Class)
|
if o.isinstance(er.Function, er.Instance, er.Class)
|
||||||
or isinstance(o, compiled.PyObject) and o.type() != 'module']
|
or isinstance(o, compiled.CompiledObject) and o.type() != 'module']
|
||||||
|
|
||||||
def _func_call_and_param_index(self):
|
def _func_call_and_param_index(self):
|
||||||
debug.speed('func_call start')
|
debug.speed('func_call start')
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ class BaseDefinition(object):
|
|||||||
"""
|
"""
|
||||||
# generate the type
|
# generate the type
|
||||||
stripped = self._definition
|
stripped = self._definition
|
||||||
if isinstance(stripped, compiled.PyObject):
|
if isinstance(stripped, compiled.CompiledObject):
|
||||||
return stripped.type()
|
return stripped.type()
|
||||||
if isinstance(stripped, er.InstanceElement):
|
if isinstance(stripped, er.InstanceElement):
|
||||||
stripped = stripped.var
|
stripped = stripped.var
|
||||||
@@ -183,7 +183,7 @@ class BaseDefinition(object):
|
|||||||
|
|
||||||
def in_builtin_module(self):
|
def in_builtin_module(self):
|
||||||
"""Whether this is a builtin module."""
|
"""Whether this is a builtin module."""
|
||||||
return isinstance(self._module, compiled.PyObject)
|
return isinstance(self._module, compiled.CompiledObject)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def line_nr(self):
|
def line_nr(self):
|
||||||
@@ -440,7 +440,7 @@ class Definition(BaseDefinition):
|
|||||||
if isinstance(d, er.InstanceElement):
|
if isinstance(d, er.InstanceElement):
|
||||||
d = d.var
|
d = d.var
|
||||||
|
|
||||||
if isinstance(d, compiled.PyObject):
|
if isinstance(d, compiled.CompiledObject):
|
||||||
return d.name
|
return d.name
|
||||||
elif isinstance(d, pr.Name):
|
elif isinstance(d, pr.Name):
|
||||||
return d.names[-1] if d.names else None
|
return d.names[-1] if d.names else None
|
||||||
@@ -496,7 +496,7 @@ class Definition(BaseDefinition):
|
|||||||
if isinstance(d, pr.Name):
|
if isinstance(d, pr.Name):
|
||||||
d = d.parent
|
d = d.parent
|
||||||
|
|
||||||
if isinstance(d, compiled.PyObject):
|
if isinstance(d, compiled.CompiledObject):
|
||||||
d = d.type() + ' ' + d.name
|
d = d.type() + ' ' + d.name
|
||||||
elif isinstance(d, iterable.Array):
|
elif isinstance(d, iterable.Array):
|
||||||
d = 'class ' + d.type
|
d = 'class ' + d.type
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ class Evaluator(object):
|
|||||||
true (default).
|
true (default).
|
||||||
|
|
||||||
>>> pairs[2] #doctest: +ELLIPSIS
|
>>> pairs[2] #doctest: +ELLIPSIS
|
||||||
(<Builtin: ...builtin...>, [<PyName: ...>, ...])
|
(<Builtin: ...builtin...>, [<CompiledName: ...>, ...])
|
||||||
|
|
||||||
:rtype: [(pr.Scope, [pr.Name])]
|
:rtype: [(pr.Scope, [pr.Name])]
|
||||||
:return: Return an generator that yields a pair of scope and names.
|
:return: Return an generator that yields a pair of scope and names.
|
||||||
@@ -147,7 +147,7 @@ class Evaluator(object):
|
|||||||
or scope.isinstance(pr.Flow)
|
or scope.isinstance(pr.Flow)
|
||||||
or scope.isinstance(er.Instance)
|
or scope.isinstance(er.Instance)
|
||||||
and non_flow.isinstance(er.Function)
|
and non_flow.isinstance(er.Function)
|
||||||
or isinstance(scope, compiled.PyObject)
|
or isinstance(scope, compiled.CompiledObject)
|
||||||
and scope.type() == 'class' and in_func_scope != scope):
|
and scope.type() == 'class' and in_func_scope != scope):
|
||||||
try:
|
try:
|
||||||
if isinstance(scope, er.Instance):
|
if isinstance(scope, er.Instance):
|
||||||
@@ -267,7 +267,7 @@ class Evaluator(object):
|
|||||||
er.Function, er.Class, er.Instance, iterable.ArrayInstance):
|
er.Function, er.Class, er.Instance, iterable.ArrayInstance):
|
||||||
result.append(call)
|
result.append(call)
|
||||||
# The string tokens are just operations (+, -, etc.)
|
# The string tokens are just operations (+, -, etc.)
|
||||||
elif isinstance(call, compiled.PyObject):
|
elif isinstance(call, compiled.CompiledObject):
|
||||||
result.append(call)
|
result.append(call)
|
||||||
elif not isinstance(call, (str, unicode)):
|
elif not isinstance(call, (str, unicode)):
|
||||||
if isinstance(call, pr.Call) and str(call.name) == 'if':
|
if isinstance(call, pr.Call) and str(call.name) == 'if':
|
||||||
@@ -284,7 +284,7 @@ class Evaluator(object):
|
|||||||
result += self.eval_call(call)
|
result += self.eval_call(call)
|
||||||
elif call == '*':
|
elif call == '*':
|
||||||
if [r for r in result if isinstance(r, iterable.Array)
|
if [r for r in result if isinstance(r, iterable.Array)
|
||||||
or isinstance(r, compiled.PyObject)
|
or isinstance(r, compiled.CompiledObject)
|
||||||
and isinstance(r.obj, (str, unicode))]:
|
and isinstance(r.obj, (str, unicode))]:
|
||||||
# if it is an iterable, ignore * operations
|
# if it is an iterable, ignore * operations
|
||||||
next(calls_iterator)
|
next(calls_iterator)
|
||||||
@@ -391,7 +391,7 @@ class Evaluator(object):
|
|||||||
except stdlib.NotInStdLib:
|
except stdlib.NotInStdLib:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if obj.isinstance(compiled.PyObject):
|
if obj.isinstance(compiled.CompiledObject):
|
||||||
if obj.is_executable_class():
|
if obj.is_executable_class():
|
||||||
return [er.Instance(self, obj, params)]
|
return [er.Instance(self, obj, params)]
|
||||||
else:
|
else:
|
||||||
@@ -453,9 +453,9 @@ def filter_private_variable(scope, call_scope, var_name):
|
|||||||
"""private variables begin with a double underline `__`"""
|
"""private variables begin with a double underline `__`"""
|
||||||
if isinstance(var_name, (str, unicode)) and isinstance(scope, er.Instance)\
|
if isinstance(var_name, (str, unicode)) and isinstance(scope, er.Instance)\
|
||||||
and var_name.startswith('__') and not var_name.endswith('__'):
|
and var_name.startswith('__') and not var_name.endswith('__'):
|
||||||
s = call_scope.get_parent_until((pr.Class, er.Instance, compiled.PyObject))
|
s = call_scope.get_parent_until((pr.Class, er.Instance, compiled.CompiledObject))
|
||||||
if s != scope:
|
if s != scope:
|
||||||
if isinstance(scope.base, compiled.PyObject):
|
if isinstance(scope.base, compiled.CompiledObject):
|
||||||
if s != scope.base:
|
if s != scope.base:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from jedi.evaluate.sys_path import get_sys_path
|
|||||||
from . import fake
|
from . import fake
|
||||||
|
|
||||||
|
|
||||||
class PyObject(Base):
|
class CompiledObject(Base):
|
||||||
# comply with the parser
|
# comply with the parser
|
||||||
start_pos = 0, 0
|
start_pos = 0, 0
|
||||||
asserts = []
|
asserts = []
|
||||||
@@ -54,7 +54,7 @@ class PyObject(Base):
|
|||||||
|
|
||||||
@underscore_memoization
|
@underscore_memoization
|
||||||
def _cls(self):
|
def _cls(self):
|
||||||
# Ensures that a PyObject is returned that is not an instance (like list)
|
# Ensures that a CompiledObject is returned that is not an instance (like list)
|
||||||
if fake.is_class_instance(self.obj):
|
if fake.is_class_instance(self.obj):
|
||||||
try:
|
try:
|
||||||
c = self.obj.__class__
|
c = self.obj.__class__
|
||||||
@@ -62,13 +62,13 @@ class PyObject(Base):
|
|||||||
# happens with numpy.core.umath._UFUNC_API (you get it
|
# happens with numpy.core.umath._UFUNC_API (you get it
|
||||||
# automatically by doing `import numpy`.
|
# automatically by doing `import numpy`.
|
||||||
c = type(None)
|
c = type(None)
|
||||||
return PyObject(c, self.parent)
|
return CompiledObject(c, self.parent)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_defined_names(self):
|
def get_defined_names(self):
|
||||||
cls = self._cls()
|
cls = self._cls()
|
||||||
for name in dir(cls.obj):
|
for name in dir(cls.obj):
|
||||||
yield PyName(cls, name)
|
yield CompiledName(cls, name)
|
||||||
|
|
||||||
def instance_names(self):
|
def instance_names(self):
|
||||||
# TODO REMOVE (temporary until the Instance method is removed)
|
# TODO REMOVE (temporary until the Instance method is removed)
|
||||||
@@ -76,7 +76,7 @@ class PyObject(Base):
|
|||||||
|
|
||||||
def get_subscope_by_name(self, name):
|
def get_subscope_by_name(self, name):
|
||||||
if name in dir(self._cls().obj):
|
if name in dir(self._cls().obj):
|
||||||
return PyName(self._cls(), name).parent
|
return CompiledName(self._cls(), name).parent
|
||||||
else:
|
else:
|
||||||
raise KeyError("CompiledObject doesn't have an attribute '%s'." % name)
|
raise KeyError("CompiledObject doesn't have an attribute '%s'." % name)
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ class PyObject(Base):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
if isinstance(bltn_obj, PyObject):
|
if isinstance(bltn_obj, CompiledObject):
|
||||||
yield bltn_obj
|
yield bltn_obj
|
||||||
else:
|
else:
|
||||||
for result in evaluator.execute(bltn_obj, params):
|
for result in evaluator.execute(bltn_obj, params):
|
||||||
@@ -123,7 +123,7 @@ class PyObject(Base):
|
|||||||
return [] # Builtins don't have imports
|
return [] # Builtins don't have imports
|
||||||
|
|
||||||
|
|
||||||
class PyName(object):
|
class CompiledName(object):
|
||||||
def __init__(self, obj, name):
|
def __init__(self, obj, name):
|
||||||
self._obj = obj
|
self._obj = obj
|
||||||
self.name = name
|
self.name = name
|
||||||
@@ -186,7 +186,7 @@ def load_module(path, name):
|
|||||||
# directly. -> github issue #59
|
# directly. -> github issue #59
|
||||||
module = sys.modules[name]
|
module = sys.modules[name]
|
||||||
sys.path = temp
|
sys.path = temp
|
||||||
return PyObject(module)
|
return CompiledObject(module)
|
||||||
|
|
||||||
|
|
||||||
docstr_defaults = {
|
docstr_defaults = {
|
||||||
@@ -258,7 +258,7 @@ def _parse_function_doc(doc):
|
|||||||
return param_str, ret
|
return param_str, ret
|
||||||
|
|
||||||
|
|
||||||
class Builtin(PyObject):
|
class Builtin(CompiledObject):
|
||||||
def get_defined_names(self):
|
def get_defined_names(self):
|
||||||
# Filter None, because it's really just a keyword, nobody wants to
|
# Filter None, because it's really just a keyword, nobody wants to
|
||||||
# access it.
|
# access it.
|
||||||
@@ -266,7 +266,7 @@ class Builtin(PyObject):
|
|||||||
|
|
||||||
|
|
||||||
builtin = Builtin(_builtins)
|
builtin = Builtin(_builtins)
|
||||||
magic_function_class = PyObject(type(load_module), parent=builtin)
|
magic_function_class = CompiledObject(type(load_module), parent=builtin)
|
||||||
|
|
||||||
|
|
||||||
def _create_from_name(module, parent, name):
|
def _create_from_name(module, parent, name):
|
||||||
@@ -283,7 +283,7 @@ def _create_from_name(module, parent, name):
|
|||||||
# PyQt4.QtGui.QStyleOptionComboBox.currentText
|
# PyQt4.QtGui.QStyleOptionComboBox.currentText
|
||||||
# -> just set it to None
|
# -> just set it to None
|
||||||
obj = None
|
obj = None
|
||||||
return PyObject(obj, parent)
|
return CompiledObject(obj, parent)
|
||||||
|
|
||||||
|
|
||||||
def create(obj, parent=builtin, module=None):
|
def create(obj, parent=builtin, module=None):
|
||||||
@@ -297,4 +297,4 @@ def create(obj, parent=builtin, module=None):
|
|||||||
faked.parent = parent
|
faked.parent = parent
|
||||||
return faked
|
return faked
|
||||||
|
|
||||||
return PyObject(obj, parent)
|
return CompiledObject(obj, parent)
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class NameFinder(object):
|
|||||||
if not result and isinstance(self.scope, er.Instance):
|
if not result and isinstance(self.scope, er.Instance):
|
||||||
# __getattr__ / __getattribute__
|
# __getattr__ / __getattribute__
|
||||||
for r in self._check_getattr(self.scope):
|
for r in self._check_getattr(self.scope):
|
||||||
if not isinstance(r, compiled.PyObject):
|
if not isinstance(r, compiled.CompiledObject):
|
||||||
new_name = copy.copy(r.name)
|
new_name = copy.copy(r.name)
|
||||||
new_name.parent = r
|
new_name.parent = r
|
||||||
result.append(new_name)
|
result.append(new_name)
|
||||||
|
|||||||
@@ -436,7 +436,7 @@ def get_modules_containing_name(mods, name):
|
|||||||
return load_module(path, source)
|
return load_module(path, source)
|
||||||
|
|
||||||
# skip non python modules
|
# skip non python modules
|
||||||
mods = set(m for m in mods if not isinstance(m, compiled.PyObject))
|
mods = set(m for m in mods if not isinstance(m, compiled.CompiledObject))
|
||||||
mod_paths = set()
|
mod_paths = set()
|
||||||
for m in mods:
|
for m in mods:
|
||||||
mod_paths.add(m.path)
|
mod_paths.add(m.path)
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
# This is indexing only one element, with a fixed index number,
|
# This is indexing only one element, with a fixed index number,
|
||||||
# otherwise it just ignores the index (e.g. [1+1]).
|
# otherwise it just ignores the index (e.g. [1+1]).
|
||||||
index = index_possibilities[0]
|
index = index_possibilities[0]
|
||||||
if isinstance(index, compiled.PyObject) \
|
if isinstance(index, compiled.CompiledObject) \
|
||||||
and isinstance(index.obj, (int, str, unicode)):
|
and isinstance(index.obj, (int, str, unicode)):
|
||||||
with common.ignored(KeyError, IndexError, TypeError):
|
with common.ignored(KeyError, IndexError, TypeError):
|
||||||
return self.get_exact_index_types(index.obj)
|
return self.get_exact_index_types(index.obj)
|
||||||
@@ -230,7 +230,7 @@ def _check_array_additions(evaluator, compare_array, module, is_list):
|
|||||||
>>> a = [""]
|
>>> a = [""]
|
||||||
>>> a.append(1)
|
>>> a.append(1)
|
||||||
"""
|
"""
|
||||||
if not settings.dynamic_array_additions or isinstance(module, compiled.PyObject):
|
if not settings.dynamic_array_additions or isinstance(module, compiled.CompiledObject):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def check_calls(calls, add_name):
|
def check_calls(calls, add_name):
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
|
|||||||
if n.names[0] == self_name and len(n.names) == 2:
|
if n.names[0] == self_name and len(n.names) == 2:
|
||||||
add_self_dot_name(n)
|
add_self_dot_name(n)
|
||||||
|
|
||||||
if not isinstance(self.base, compiled.PyObject):
|
if not isinstance(self.base, compiled.CompiledObject):
|
||||||
for s in self.base.get_super_classes():
|
for s in self.base.get_super_classes():
|
||||||
for inst in self._evaluator.execute(s):
|
for inst in self._evaluator.execute(s):
|
||||||
names += inst.get_self_attributes()
|
names += inst.get_self_attributes()
|
||||||
@@ -201,7 +201,7 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
or isinstance(par, pr.Class) \
|
or isinstance(par, pr.Class) \
|
||||||
and par == self.instance.base.base:
|
and par == self.instance.base.base:
|
||||||
par = self.instance
|
par = self.instance
|
||||||
elif not isinstance(par, (pr.Module, compiled.PyObject)):
|
elif not isinstance(par, (pr.Module, compiled.CompiledObject)):
|
||||||
par = InstanceElement(self.instance._evaluator, self.instance, par, self.is_class_var)
|
par = InstanceElement(self.instance._evaluator, self.instance, par, self.is_class_var)
|
||||||
return par
|
return par
|
||||||
|
|
||||||
@@ -277,7 +277,7 @@ class Class(use_metaclass(CachedMetaClass, pr.IsScope)):
|
|||||||
# TODO mro!
|
# TODO mro!
|
||||||
for cls in self.get_super_classes():
|
for cls in self.get_super_classes():
|
||||||
# Get the inherited names.
|
# Get the inherited names.
|
||||||
if isinstance(cls, compiled.PyObject):
|
if isinstance(cls, compiled.CompiledObject):
|
||||||
super_result += cls.get_defined_names()
|
super_result += cls.get_defined_names()
|
||||||
else:
|
else:
|
||||||
for i in cls.instance_names():
|
for i in cls.instance_names():
|
||||||
|
|||||||
@@ -45,13 +45,13 @@ def builtins_getattr(evaluator, obj, params):
|
|||||||
objects = _follow_param(evaluator, params, 0)
|
objects = _follow_param(evaluator, params, 0)
|
||||||
names = _follow_param(evaluator, params, 1)
|
names = _follow_param(evaluator, params, 1)
|
||||||
for obj in objects:
|
for obj in objects:
|
||||||
if not isinstance(obj, (er.Instance, er.Class, pr.Module, compiled.PyObject)):
|
if not isinstance(obj, (er.Instance, er.Class, pr.Module, compiled.CompiledObject)):
|
||||||
debug.warning('getattr called without instance')
|
debug.warning('getattr called without instance')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
s = unicode, str
|
s = unicode, str
|
||||||
if isinstance(name, compiled.PyObject) and isinstance(name.obj, s):
|
if isinstance(name, compiled.CompiledObject) and isinstance(name.obj, s):
|
||||||
stmts += evaluator.follow_path(iter([name.obj]), [obj], obj)
|
stmts += evaluator.follow_path(iter([name.obj]), [obj], obj)
|
||||||
else:
|
else:
|
||||||
debug.warning('getattr called without str')
|
debug.warning('getattr called without str')
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ from jedi.evaluate import Evaluator
|
|||||||
|
|
||||||
def test_simple():
|
def test_simple():
|
||||||
e = Evaluator()
|
e = Evaluator()
|
||||||
bltn = compiled.PyObject(builtins)
|
bltn = compiled.CompiledObject(builtins)
|
||||||
obj = compiled.PyObject('_str_', bltn)
|
obj = compiled.CompiledObject('_str_', bltn)
|
||||||
upper = e.find_types(obj, 'upper')
|
upper = e.find_types(obj, 'upper')
|
||||||
assert len(upper) == 1
|
assert len(upper) == 1
|
||||||
objs = list(e.execute(upper[0]))
|
objs = list(e.execute(upper[0]))
|
||||||
|
|||||||
Reference in New Issue
Block a user