mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-16 21:44:56 +08:00
Simplify code
This commit is contained in:
@@ -328,30 +328,8 @@ def load_module(path, name):
|
|||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
# RuntimeError: the PyQt4.QtCore and PyQt5.QtCore modules both wrap
|
# RuntimeError: the PyQt4.QtCore and PyQt5.QtCore modules both wrap
|
||||||
# the QObject class
|
# the QObject class
|
||||||
if 'PySide' in dotted_path or 'PyQt4' in dotted_path:
|
if 'PySide' in dotted_path or 'PyQt' in dotted_path:
|
||||||
original_path = dotted_path
|
return None
|
||||||
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
|
# Just access the cache after import, because of #59 as well as the very
|
||||||
# complicated import structure of Python.
|
# complicated import structure of Python.
|
||||||
module = sys.modules[dotted_path]
|
module = sys.modules[dotted_path]
|
||||||
|
|||||||
@@ -186,6 +186,9 @@ class ImportWrapper(pr.Base):
|
|||||||
analysis.add(self._evaluator, 'import-error', e.name_part)
|
analysis.add(self._evaluator, 'import-error', e.name_part)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
if module is None:
|
||||||
|
return []
|
||||||
|
|
||||||
if self.import_stmt.is_nested() and not self.nested_resolve:
|
if self.import_stmt.is_nested() and not self.nested_resolve:
|
||||||
scopes = [NestedImportModule(module, self.import_stmt)]
|
scopes = [NestedImportModule(module, self.import_stmt)]
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user