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