mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
It was not possible to load PyQt4, now it works fine.
This commit is contained in:
84
builtin.py
84
builtin.py
@@ -85,28 +85,64 @@ class Parser(CachedModule):
|
|||||||
super(Parser, self).__init__(path=path, name=name)
|
super(Parser, self).__init__(path=path, name=name)
|
||||||
|
|
||||||
self.sys_path = sys_path
|
self.sys_path = sys_path
|
||||||
self._content = {}
|
|
||||||
self._module = None
|
self._module = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def module(self):
|
def module(self):
|
||||||
if not self._module:
|
def possible_python_path(path, offset=0):
|
||||||
if self.path:
|
dot_path = []
|
||||||
dir = os.path.dirname(self.path)
|
p = self.path
|
||||||
self.sys_path.insert(0, dir)
|
while p not in sys.path[offset:]:
|
||||||
|
p, sep, mod = p.rpartition(os.path.sep)
|
||||||
|
dot_path.append(mod.partition('.')[0])
|
||||||
|
return ".".join(reversed(dot_path))
|
||||||
|
|
||||||
|
def load_module(name, path=None):
|
||||||
|
""" Returns True if it is successful. """
|
||||||
|
if path:
|
||||||
|
self.sys_path.insert(0, path)
|
||||||
|
|
||||||
temp, sys.path = sys.path, self.sys_path
|
temp, sys.path = sys.path, self.sys_path
|
||||||
# TODO reenable and check (stackoverflow question - pylab builtins)
|
# TODO reenable and check (stackoverflow question - pylab builtins)
|
||||||
#print 'sypa', sys.path
|
self.content = {}
|
||||||
exec_function('import %s as module' % self.name, self._content)
|
try:
|
||||||
|
exec_function('import %s as module' % name, self.content)
|
||||||
|
except SystemError:
|
||||||
|
# this happens e.g. when loading PyQt4.QtCore. Somehow it needs
|
||||||
|
# the full path
|
||||||
|
if not self.path:
|
||||||
|
raise # this case is not covered
|
||||||
|
try:
|
||||||
|
# in the case of PyQt, the module is loaded anyway...
|
||||||
|
self._module = sys.modules[possible_python_path(path, 1)]
|
||||||
|
debug.warning('Loaded a module with SystemError.')
|
||||||
|
entries = True
|
||||||
|
except KeyError:
|
||||||
|
entries = False
|
||||||
|
else:
|
||||||
|
# entries may not be defined:
|
||||||
|
# http://stackoverflow.com/questions/10182743\
|
||||||
|
# /python-import-internals-difference
|
||||||
|
self._module = self.content['module']
|
||||||
|
entries = [e for e in dir(self._module)
|
||||||
|
if not e.startswith('__')]
|
||||||
|
|
||||||
self.sys_path, sys.path = sys.path, temp
|
self.sys_path, sys.path = sys.path, temp
|
||||||
|
if path:
|
||||||
if self.path:
|
|
||||||
self.sys_path.pop(0)
|
self.sys_path.pop(0)
|
||||||
|
|
||||||
self._module = self._content['module']
|
return bool(entries)
|
||||||
#print 'mod', self._content['module']
|
|
||||||
|
if not self._module:
|
||||||
|
path = self.path
|
||||||
|
if self.path:
|
||||||
|
path = os.path.dirname(self.path)
|
||||||
|
|
||||||
|
if not load_module(self.name, path):
|
||||||
|
if not load_module(possible_python_path(path)):
|
||||||
|
raise ImportError('Import problems with builtins?')
|
||||||
|
|
||||||
|
|
||||||
return self._module
|
return self._module
|
||||||
|
|
||||||
def _get_source(self):
|
def _get_source(self):
|
||||||
@@ -180,16 +216,24 @@ class Parser(CachedModule):
|
|||||||
for n in names:
|
for n in names:
|
||||||
if '__' in n and n not in mixin_funcs:
|
if '__' in n and n not in mixin_funcs:
|
||||||
continue
|
continue
|
||||||
# this has a builtin_function_or_method
|
try:
|
||||||
exe = getattr(scope, n)
|
# this has a builtin_function_or_method
|
||||||
if inspect.isbuiltin(exe) or inspect.ismethoddescriptor(exe):
|
exe = getattr(scope, n)
|
||||||
funcs[n] = exe
|
except AttributeError:
|
||||||
elif inspect.isclass(exe):
|
# happens e.g. in properties of
|
||||||
classes[n] = exe
|
# PyQt4.QtGui.QStyleOptionComboBox.currentText
|
||||||
elif inspect.ismemberdescriptor(exe):
|
# -> just set it to None
|
||||||
members[n] = exe
|
members[n] = None
|
||||||
else:
|
else:
|
||||||
stmts[n] = exe
|
if inspect.isbuiltin(exe) \
|
||||||
|
or inspect.ismethoddescriptor(exe):
|
||||||
|
funcs[n] = exe
|
||||||
|
elif inspect.isclass(exe):
|
||||||
|
classes[n] = exe
|
||||||
|
elif inspect.ismemberdescriptor(exe):
|
||||||
|
members[n] = exe
|
||||||
|
else:
|
||||||
|
stmts[n] = exe
|
||||||
return classes, funcs, stmts, members
|
return classes, funcs, stmts, members
|
||||||
|
|
||||||
code = ''
|
code = ''
|
||||||
|
|||||||
20
test/completion/thirdparty/PyQt4.py
vendored
Normal file
20
test/completion/thirdparty/PyQt4.py
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
from PyQt4.QtCore import *
|
||||||
|
from PyQt4.QtGui import *
|
||||||
|
|
||||||
|
#? ['QActionGroup']
|
||||||
|
QActionGroup
|
||||||
|
|
||||||
|
#? ['currentText']
|
||||||
|
QStyleOptionComboBox().currentText
|
||||||
|
|
||||||
|
#? []
|
||||||
|
QStyleOptionComboBox().currentText.
|
||||||
|
|
||||||
|
from PyQt4 import QtGui
|
||||||
|
|
||||||
|
#? ['currentText']
|
||||||
|
QtGui.QStyleOptionComboBox().currentText
|
||||||
|
|
||||||
|
#? []
|
||||||
|
QtGui.QStyleOptionComboBox().currentText.
|
||||||
|
|
||||||
Reference in New Issue
Block a user