mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 07:41:51 +08:00
better environment for compiled executions
This commit is contained in:
@@ -83,6 +83,7 @@ from jedi.evaluate import iterable
|
|||||||
from jedi.evaluate.cache import memoize_default
|
from jedi.evaluate.cache import memoize_default
|
||||||
from jedi.evaluate import stdlib
|
from jedi.evaluate import stdlib
|
||||||
from jedi.evaluate import finder
|
from jedi.evaluate import finder
|
||||||
|
from jedi.evaluate import compiled
|
||||||
|
|
||||||
|
|
||||||
class Evaluator(object):
|
class Evaluator(object):
|
||||||
@@ -391,7 +392,9 @@ class Evaluator(object):
|
|||||||
except stdlib.NotInStdLib:
|
except stdlib.NotInStdLib:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if obj.isinstance(er.Class):
|
if isinstance(obj, compiled.PyObject):
|
||||||
|
return obj.execute(params)
|
||||||
|
elif obj.isinstance(er.Class):
|
||||||
# There maybe executions of executions.
|
# There maybe executions of executions.
|
||||||
return [er.Instance(self, obj, params)]
|
return [er.Instance(self, obj, params)]
|
||||||
elif isinstance(obj, iterable.Generator):
|
elif isinstance(obj, iterable.Generator):
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
"""
|
"""
|
||||||
Imitate the parser representation.
|
Imitate the parser representation.
|
||||||
"""
|
"""
|
||||||
|
import inspect
|
||||||
|
|
||||||
|
from jedi._compatibility import builtins
|
||||||
from jedi.cache import underscore_memoization
|
from jedi.cache import underscore_memoization
|
||||||
|
|
||||||
|
|
||||||
class PyObject(object):
|
class PyObject(object):
|
||||||
def __init__(self, obj, parent=None):
|
def __init__(self, obj, parent=None, instantiated=False):
|
||||||
self.obj = obj
|
self.obj = obj
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
self.instantiated = instantiated
|
||||||
|
|
||||||
def get_defined_names(self):
|
def get_defined_names(self):
|
||||||
for name in dir(self.obj):
|
for name in dir(self.obj):
|
||||||
@@ -16,6 +20,21 @@ class PyObject(object):
|
|||||||
def isinstance(self, *obj):
|
def isinstance(self, *obj):
|
||||||
return isinstance(self, obj)
|
return isinstance(self, obj)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
# might not exist sometimes (raises AttributeError)
|
||||||
|
return self.obj.__name__
|
||||||
|
|
||||||
|
def execute(self, params):
|
||||||
|
if inspect.isclass(self.obj):
|
||||||
|
return [PyObject(self.obj, self.parent, True)]
|
||||||
|
elif inspect.isbuiltin(self.obj) or inspect.ismethod(self.obj) \
|
||||||
|
or inspect.ismethoddescriptor(self.obj):
|
||||||
|
return []
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
class PyName(object):
|
class PyName(object):
|
||||||
def __init__(self, obj, name):
|
def __init__(self, obj, name):
|
||||||
@@ -27,7 +46,17 @@ class PyName(object):
|
|||||||
@property
|
@property
|
||||||
@underscore_memoization
|
@underscore_memoization
|
||||||
def parent(self):
|
def parent(self):
|
||||||
return PyObject(getattr(self._obj.obj, self._name), self._obj)
|
try:
|
||||||
|
# this has a builtin_function_or_method
|
||||||
|
o = getattr(self._obj.obj, self._name)
|
||||||
|
except AttributeError:
|
||||||
|
# happens e.g. in properties of
|
||||||
|
# PyQt4.QtGui.QStyleOptionComboBox.currentText
|
||||||
|
# -> just set it to None
|
||||||
|
return PyObject(obj, py_builtin)
|
||||||
|
return PyObject(o, self._obj)
|
||||||
|
|
||||||
def get_code(self):
|
def get_code(self):
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
|
py_builtin = PyObject(builtins)
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ from jedi.evaluate import Evaluator
|
|||||||
|
|
||||||
|
|
||||||
def test_simple():
|
def test_simple():
|
||||||
|
e = Evaluator()
|
||||||
bltn = compiled.PyObject(builtins)
|
bltn = compiled.PyObject(builtins)
|
||||||
obj = compiled.PyObject('_str_', bltn)
|
obj = compiled.PyObject('_str_', bltn)
|
||||||
upper = Evaluator().find_types(obj, 'upper')
|
upper = e.find_types(obj, 'upper')
|
||||||
assert len(upper) == 1
|
assert len(upper) == 1
|
||||||
|
objs = e.execute(upper[0])
|
||||||
|
assert len(objs) == 1
|
||||||
|
assert isinstance(objs[0].obj, str)
|
||||||
|
|||||||
Reference in New Issue
Block a user