From fb8638889002f9fd816d40ab2ca123c85a11b95a Mon Sep 17 00:00:00 2001 From: ColinDuquesnoy Date: Sat, 13 Sep 2014 12:18:34 +0200 Subject: [PATCH 1/3] Fix RuntimeError: the PyQt5.QtCore and PyQt4.QtCore modules both wrap the QObject class --- jedi/evaluate/compiled/__init__.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/jedi/evaluate/compiled/__init__.py b/jedi/evaluate/compiled/__init__.py index 480eb1a7..ddbd4165 100644 --- a/jedi/evaluate/compiled/__init__.py +++ b/jedi/evaluate/compiled/__init__.py @@ -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] From d1ae4473620c7e6ea2684435f2e2a74ff38a1593 Mon Sep 17 00:00:00 2001 From: ColinDuquesnoy Date: Mon, 29 Sep 2014 09:50:49 +0200 Subject: [PATCH 2/3] Simplify code --- jedi/evaluate/compiled/__init__.py | 26 ++------------------------ jedi/evaluate/imports.py | 3 +++ 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/jedi/evaluate/compiled/__init__.py b/jedi/evaluate/compiled/__init__.py index ddbd4165..05557eb8 100644 --- a/jedi/evaluate/compiled/__init__.py +++ b/jedi/evaluate/compiled/__init__.py @@ -328,30 +328,8 @@ def load_module(path, name): 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') + if 'PySide' in dotted_path or 'PyQt' in dotted_path: + return None # Just access the cache after import, because of #59 as well as the very # complicated import structure of Python. module = sys.modules[dotted_path] diff --git a/jedi/evaluate/imports.py b/jedi/evaluate/imports.py index 78841a7e..b21088ab 100644 --- a/jedi/evaluate/imports.py +++ b/jedi/evaluate/imports.py @@ -186,6 +186,9 @@ class ImportWrapper(pr.Base): analysis.add(self._evaluator, 'import-error', e.name_part) return [] + if module is None: + return [] + if self.import_stmt.is_nested() and not self.nested_resolve: scopes = [NestedImportModule(module, self.import_stmt)] else: From d7836c1034256375b67ca9eb47db1e3b28e82256 Mon Sep 17 00:00:00 2001 From: ColinDuquesnoy Date: Mon, 29 Sep 2014 11:57:38 +0200 Subject: [PATCH 3/3] Add a comment and link to issue #483 --- jedi/evaluate/compiled/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jedi/evaluate/compiled/__init__.py b/jedi/evaluate/compiled/__init__.py index be838150..66a058a7 100644 --- a/jedi/evaluate/compiled/__init__.py +++ b/jedi/evaluate/compiled/__init__.py @@ -325,9 +325,10 @@ def load_module(path, name): 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 'PyQt' in dotted_path: + # RuntimeError: the PyQt4.QtCore and PyQt5.QtCore modules both wrap + # the QObject class. + # See https://github.com/davidhalter/jedi/pull/483 return None # Just access the cache after import, because of #59 as well as the very # complicated import structure of Python.