mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-16 17:06:45 +08:00
Fix RuntimeError: the PyQt5.QtCore and PyQt4.QtCore modules both wrap the QObject class
This commit is contained in:
@@ -323,7 +323,35 @@ def load_module(path, name):
|
||||
sys_path.insert(0, p)
|
||||
|
||||
temp, sys.path = sys.path, sys_path
|
||||
__import__(dotted_path)
|
||||
try:
|
||||
__import__(dotted_path)
|
||||
except RuntimeError:
|
||||
# RuntimeError: the PyQt4.QtCore and PyQt5.QtCore modules both wrap
|
||||
# the QObject class
|
||||
if 'PySide' in dotted_path or 'PyQt4' in dotted_path:
|
||||
original_path = dotted_path
|
||||
dotted_path = dotted_path.replace('PySide', 'PyQt5')
|
||||
dotted_path = dotted_path.replace('PyQt4', 'PyQt5')
|
||||
if 'QtGui' in dotted_path:
|
||||
# special case, we need to merge QtGui and QtWidgets modules:
|
||||
# PyQt4.QtGui (or PySide.QtGui) = PyQt5.QtGui + PyQt5.QtWidgets
|
||||
__import__(dotted_path)
|
||||
# get PyQt5.QtGui
|
||||
qt_gui_module = sys.modules[dotted_path]
|
||||
# get PyQt5.QtWidgets
|
||||
dotted_path = dotted_path.replace('QtGui', 'QtWidgets')
|
||||
__import__(dotted_path)
|
||||
module_widgets = sys.modules[dotted_path]
|
||||
# merge modules into PySide.QtGui or PyQt4.QtGui
|
||||
qt_gui_module.__dict__.update(module_widgets.__dict__)
|
||||
sys.modules[original_path] = qt_gui_module
|
||||
return CompiledObject(qt_gui_module)
|
||||
else:
|
||||
dotted_path = dotted_path.replace('PyQt5', 'PyQt4')
|
||||
if 'QtWidgets' in dotted_path:
|
||||
# PyQt4.QtWidgets does not exists but all names can be found
|
||||
# in QtGui
|
||||
dotted_path = dotted_path.replace('QtWidgets', 'QtGui')
|
||||
# Just access the cache after import, because of #59 as well as the very
|
||||
# complicated import structure of Python.
|
||||
module = sys.modules[dotted_path]
|
||||
|
||||
Reference in New Issue
Block a user