1
0
forked from VimPlug/jedi

tried to start introducing the compiled module to the library

This commit is contained in:
Dave Halter
2014-01-09 01:26:51 +01:00
parent 3017e72b86
commit 0cb23dcfa2
3 changed files with 25 additions and 18 deletions

View File

@@ -14,6 +14,7 @@ from jedi import cache
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.evaluate import imports from jedi.evaluate import imports
from jedi.evaluate import compiled
from jedi import keywords from jedi import keywords
@@ -70,8 +71,11 @@ class BaseDefinition(object):
# generate a path to the definition # generate a path to the definition
self._module = definition.get_parent_until() self._module = definition.get_parent_until()
self.module_path = self._module.path if self.in_builtin_module():
"""Shows the file path of a module. e.g. ``/usr/lib/python2.7/os.py``""" self.module_path = None
else:
self.module_path = self._module.path
"""Shows the file path of a module. e.g. ``/usr/lib/python2.7/os.py``"""
@property @property
def start_pos(self): def start_pos(self):
@@ -177,8 +181,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 not (self.module_path is None or return isinstance(self._module, compiled.PyObject)
self.module_path.endswith('.py'))
@property @property
def line_nr(self): def line_nr(self):
@@ -518,12 +521,7 @@ class Definition(BaseDefinition):
.. todo:: Add full path. This function is should return a .. todo:: Add full path. This function is should return a
`module.class.function` path. `module.class.function` path.
""" """
if self.module_path.endswith('.py') \ position = '' if self.in_builtin_module else '@%s' % (self.line)
and not isinstance(self._definition, pr.Module):
position = '@%s' % (self.line)
else:
# is a builtin or module
position = ''
return "%s:%s%s" % (self.module_name, self.description, position) return "%s:%s%s" % (self.module_name, self.description, position)
def defined_names(self): def defined_names(self):

View File

@@ -174,8 +174,7 @@ class Evaluator(object):
# Add builtins to the global scope. # Add builtins to the global scope.
if include_builtin: if include_builtin:
builtin_scope = builtin.Builtin.scope yield compiled.builtin, compiled.builtin.get_defined_names()
yield builtin_scope, builtin_scope.get_defined_names()
def find_types(self, scope, name_str, position=None, search_global=False, def find_types(self, scope, name_str, position=None, search_global=False,
is_goto=False, resolve_decorator=True): is_goto=False, resolve_decorator=True):

View File

@@ -6,6 +6,7 @@ import re
from jedi._compatibility import builtins as _builtins, is_py3k from jedi._compatibility import builtins as _builtins, is_py3k
from jedi import debug from jedi import debug
from jedi.parser.representation import Base
from jedi.cache import underscore_memoization from jedi.cache import underscore_memoization
@@ -13,13 +14,17 @@ from jedi.cache import underscore_memoization
# unbound methods such as pyqtSignals have no __name__ # unbound methods such as pyqtSignals have no __name__
# if not hasattr(func, "__name__"): # if not hasattr(func, "__name__"):
class PyObject(object): class PyObject(Base):
def __init__(self, obj, parent=None, instantiated=False): def __init__(self, obj, parent=None, instantiated=False):
self.obj = obj self.obj = obj
self.parent = parent self.parent = parent
self.instantiated = instantiated self.instantiated = instantiated
self.doc = inspect.getdoc(obj) self.doc = inspect.getdoc(obj)
# comply with the parser
self.get_parent_until = lambda: parent
self.start_pos = 0, 0
def __repr__(self): def __repr__(self):
return '<%s: %s>' % (type(self).__name__, self.obj) return '<%s: %s>' % (type(self).__name__, self.obj)
@@ -30,19 +35,25 @@ class PyObject(object):
return _parse_function_doc(self.doc) return _parse_function_doc(self.doc)
def type(self):
if inspect.isclass(self.obj):
return 'class'
elif inspect.ismodule(self.obj):
return 'module'
elif inspect.isbuiltin(self.obj) or inspect.ismethod(self.obj) \
or inspect.ismethoddescriptor(self.obj):
return 'def'
def get_defined_names(self): def get_defined_names(self):
# We don't want to execute properties, therefore we have to try to get # We don't want to execute properties, therefore we have to try to get
# the class # the class
cls = self cls = self
if not (inspect.isclass(self.obj) or inspect.ismodule(self.obj)): if not inspect.isclass(self.obj):
cls = PyObject(self.obj.__class__, self.parent) cls = PyObject(self.obj.__class__, self.parent)
for name in dir(cls.obj): for name in dir(cls.obj):
yield PyName(cls, name) yield PyName(cls, name)
def isinstance(self, *obj):
return isinstance(self, obj)
@property @property
def name(self): def name(self):
# might not exist sometimes (raises AttributeError) # might not exist sometimes (raises AttributeError)
@@ -64,7 +75,6 @@ class PyName(object):
def __init__(self, obj, name): def __init__(self, obj, name):
self._obj = obj self._obj = obj
self._name = name self._name = name
self.start_pos = 0, 0 # an illegal start_pos, to make sorting easy. self.start_pos = 0, 0 # an illegal start_pos, to make sorting easy.
@property @property