summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoofar <toofar@spalge.com>2022-09-10 19:27:18 +1200
committertoofar <toofar@spalge.com>2022-09-10 20:48:39 +1200
commit4cf6aa8cef5227d3610b31144318cd78109d2809 (patch)
tree5437e041eff0873f7b9518fd7b4f107e74a17735
parent6f8d7a7fbc6350b16046b832e8f5957b349245f2 (diff)
downloadqutebrowser-4cf6aa8cef5227d3610b31144318cd78109d2809.tar.gz
qutebrowser-4cf6aa8cef5227d3610b31144318cd78109d2809.zip
Adjust import order in machinery for pyright/vscode
When pyright tags an object as "Unknown" (even if that is just one part of a union of possible definitions) then VS code doesn't provide autocompletion for that objects. Additionally, if you import that same object from multiple modules in a file pyright (or VS Code?) will go through them in order and prefer the last one. 1. if you import an object by name from two modules and that latter module isn't installed the object will be marked as "Unknown" if machinery.USE_PYQT5: # installed from PyQt5.QtWebEngineWidgets import QWebEngineHistory elif machinery.USE_PYSIDE2: # not installed from PySide2.QtWebEngineWidgets import QWebEngineHistory reveal_type(QWebEngineHistory) # class(QWebEngineHistory) | Unknown 2. if you import an object by name from a module that isn't installed and that module isn't later overridden it'll be marked as "Unknown" if machinery.USE_PYQT6: # installed from from PyQt6.QtWebEngineCore import * elif machinery.USE_PYQT5: # not installed from PyQt5.QtWebEngineWidgets import QWebEngineHistory reveal_type(QWebEngineHistory) # class(QWebEngineHistory) | Unknown if machinery.USE_PYQT5: # not installed from PyQt5.QtWebEngineWidgets import QWebEngineHistory elif machinery.USE_PYQT6: # installed from from PyQt6.QtWebEngineCore import * reveal_type(QWebEngineHistory) # class(QWebEngineHistory) So in general we want to put modules most likely to be installed at the bottom. Except if it imports an object by name and there is a possibility it won't be installed we want to bump it up. So now we have: 1. PySide6: not currently supported 2. PyQt5: main supported type checking language, but not guaranteed to be installed 3. PyQt6: quite likely to be installed but not yet supported for type checking This means that if you have both PyQt6 and PyQt5 installed you will get autocompletion from PyQt6. It might be better to get it from PyQt5 instead, since that's what we will be type checking with on CI for now, but getting no autocompletion because you only have PyQt6 installed and not PyQt5 is not ideal. You can confirm this by using the "go to definition" feature. Hopefully we can use the defineConstant configuration parameter for pyright to make this ordering less important in the future by using that to set the proffered bindings for type checking.
-rw-r--r--qutebrowser/qt/core.py6
-rw-r--r--qutebrowser/qt/dbus.py8
-rw-r--r--qutebrowser/qt/gui.py6
-rw-r--r--qutebrowser/qt/network.py6
-rw-r--r--qutebrowser/qt/opengl.py6
-rw-r--r--qutebrowser/qt/printsupport.py8
-rw-r--r--qutebrowser/qt/qml.py8
-rw-r--r--qutebrowser/qt/sip.py6
-rw-r--r--qutebrowser/qt/sql.py8
-rw-r--r--qutebrowser/qt/test.py8
-rw-r--r--qutebrowser/qt/webenginecore.py6
-rw-r--r--qutebrowser/qt/webenginewidgets.py6
-rw-r--r--qutebrowser/qt/webkit.py6
-rw-r--r--qutebrowser/qt/webkitwidgets.py6
-rw-r--r--qutebrowser/qt/widgets.py8
15 files changed, 57 insertions, 45 deletions
diff --git a/qutebrowser/qt/core.py b/qutebrowser/qt/core.py
index ab292c4f3..b09459f6f 100644
--- a/qutebrowser/qt/core.py
+++ b/qutebrowser/qt/core.py
@@ -6,11 +6,11 @@
from qutebrowser.qt import machinery
-if machinery.USE_PYQT5:
+if machinery.USE_PYSIDE6:
+ from PySide6.QtCore import *
+elif machinery.USE_PYQT5:
from PyQt5.QtCore import *
elif machinery.USE_PYQT6:
from PyQt6.QtCore import *
-elif machinery.USE_PYSIDE6:
- from PySide6.QtCore import *
else:
raise machinery.UnknownWrapper()
diff --git a/qutebrowser/qt/dbus.py b/qutebrowser/qt/dbus.py
index 4ef04d3cd..6ef8e55f3 100644
--- a/qutebrowser/qt/dbus.py
+++ b/qutebrowser/qt/dbus.py
@@ -6,9 +6,11 @@
from qutebrowser.qt import machinery
-if machinery.USE_PYQT5:
+if machinery.USE_PYSIDE6:
+ from PySide6.QtDBus import *
+elif machinery.USE_PYQT5:
from PyQt5.QtDBus import *
elif machinery.USE_PYQT6:
from PyQt6.QtDBus import *
-elif machinery.USE_PYSIDE6:
- from PySide6.QtDBus import *
+else:
+ raise machinery.UnknownWrapper()
diff --git a/qutebrowser/qt/gui.py b/qutebrowser/qt/gui.py
index 7bb37089b..ce4780f42 100644
--- a/qutebrowser/qt/gui.py
+++ b/qutebrowser/qt/gui.py
@@ -6,13 +6,13 @@
from qutebrowser.qt import machinery
-if machinery.USE_PYQT5:
+if machinery.USE_PYSIDE6:
+ from PySide6.QtGui import *
+elif machinery.USE_PYQT5:
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QFileSystemModel
del QOpenGLVersionProfile # moved to QtOpenGL in Qt 6
elif machinery.USE_PYQT6:
from PyQt6.QtGui import *
-elif machinery.USE_PYSIDE6:
- from PySide6.QtGui import *
else:
raise machinery.UnknownWrapper()
diff --git a/qutebrowser/qt/network.py b/qutebrowser/qt/network.py
index 93dd14495..6836d6226 100644
--- a/qutebrowser/qt/network.py
+++ b/qutebrowser/qt/network.py
@@ -6,11 +6,11 @@
from qutebrowser.qt import machinery
-if machinery.USE_PYQT5:
+if machinery.USE_PYSIDE6:
+ from PySide6.QtNetwork import *
+elif machinery.USE_PYQT5:
from PyQt5.QtNetwork import *
elif machinery.USE_PYQT6:
from PyQt6.QtNetwork import *
-elif machinery.USE_PYSIDE6:
- from PySide6.QtNetwork import *
else:
raise machinery.UnknownWrapper()
diff --git a/qutebrowser/qt/opengl.py b/qutebrowser/qt/opengl.py
index 7aaee3983..a04fb9a29 100644
--- a/qutebrowser/qt/opengl.py
+++ b/qutebrowser/qt/opengl.py
@@ -6,11 +6,11 @@
from qutebrowser.qt import machinery
-if machinery.USE_PYQT5:
+if machinery.USE_PYSIDE6:
+ from PySide6.QtOpenGL import *
+elif machinery.USE_PYQT5:
from PyQt5.QtGui import QOpenGLVersionProfile
elif machinery.USE_PYQT6:
from PyQt6.QtOpenGL import *
-elif machinery.USE_PYSIDE6:
- from PySide6.QtOpenGL import *
else:
raise machinery.UnknownWrapper()
diff --git a/qutebrowser/qt/printsupport.py b/qutebrowser/qt/printsupport.py
index e4b6571a3..08a29638e 100644
--- a/qutebrowser/qt/printsupport.py
+++ b/qutebrowser/qt/printsupport.py
@@ -6,9 +6,11 @@
from qutebrowser.qt import machinery
-if machinery.USE_PYQT5:
+if machinery.USE_PYSIDE6:
+ from PySide6.QtPrintSupport import *
+elif machinery.USE_PYQT5:
from PyQt5.QtPrintSupport import *
elif machinery.USE_PYQT6:
from PyQt6.QtPrintSupport import *
-elif machinery.USE_PYSIDE6:
- from PySide6.QtPrintSupport import *
+else:
+ raise machinery.UnknownWrapper()
diff --git a/qutebrowser/qt/qml.py b/qutebrowser/qt/qml.py
index 30ca7dc70..faa82df48 100644
--- a/qutebrowser/qt/qml.py
+++ b/qutebrowser/qt/qml.py
@@ -6,9 +6,11 @@
from qutebrowser.qt import machinery
-if machinery.USE_PYQT5:
+if machinery.USE_PYSIDE6:
+ from PySide6.QtQml import *
+elif machinery.USE_PYQT5:
from PyQt5.QtQml import *
elif machinery.USE_PYQT6:
from PyQt6.QtQml import *
-elif machinery.USE_PYSIDE6:
- from PySide6.QtQml import *
+else:
+ raise machinery.UnknownWrapper()
diff --git a/qutebrowser/qt/sip.py b/qutebrowser/qt/sip.py
index 65139fdd3..caf1488a7 100644
--- a/qutebrowser/qt/sip.py
+++ b/qutebrowser/qt/sip.py
@@ -8,7 +8,9 @@ from qutebrowser.qt import machinery
# While upstream recommends using PyQt6.sip ever since PyQt6 5.11, some distributions
# still package later versions of PyQt6 with a top-level "sip" rather than "PyQt6.sip".
-if machinery.USE_PYQT5:
+if machinery.USE_PYSIDE6:
+ raise machinery.Unavailable()
+elif machinery.USE_PYQT5:
try:
from PyQt5.sip import *
except ImportError:
@@ -18,7 +20,5 @@ elif machinery.USE_PYQT6:
from PyQt6.sip import *
except ImportError:
from sip import *
-elif machinery.USE_PYSIDE6:
- raise machinery.Unavailable()
else:
raise machinery.UnknownWrapper()
diff --git a/qutebrowser/qt/sql.py b/qutebrowser/qt/sql.py
index 692a8b231..a8c46ebb1 100644
--- a/qutebrowser/qt/sql.py
+++ b/qutebrowser/qt/sql.py
@@ -6,9 +6,11 @@
from qutebrowser.qt import machinery
-if machinery.USE_PYQT5:
+if machinery.USE_PYSIDE6:
+ from PySide6.QtSql import *
+elif machinery.USE_PYQT5:
from PyQt5.QtSql import *
elif machinery.USE_PYQT6:
from PyQt6.QtSql import *
-elif machinery.USE_PYSIDE6:
- from PySide6.QtSql import *
+else:
+ raise machinery.UnknownWrapper()
diff --git a/qutebrowser/qt/test.py b/qutebrowser/qt/test.py
index 0766f0ead..e8e0189d0 100644
--- a/qutebrowser/qt/test.py
+++ b/qutebrowser/qt/test.py
@@ -6,9 +6,11 @@
from qutebrowser.qt import machinery
-if machinery.USE_PYQT5:
+if machinery.USE_PYSIDE6:
+ from PySide6.QtTest import *
+elif machinery.USE_PYQT5:
from PyQt5.QtTest import *
elif machinery.USE_PYQT6:
from PyQt6.QtTest import *
-elif machinery.USE_PYSIDE6:
- from PySide6.QtTest import *
+else:
+ raise machinery.UnknownWrapper()
diff --git a/qutebrowser/qt/webenginecore.py b/qutebrowser/qt/webenginecore.py
index d63ec1c70..b1e650d24 100644
--- a/qutebrowser/qt/webenginecore.py
+++ b/qutebrowser/qt/webenginecore.py
@@ -6,7 +6,9 @@
from qutebrowser.qt import machinery
-if machinery.USE_PYQT5:
+if machinery.USE_PYSIDE6:
+ from PySide6.QtWebEngineCore import *
+elif machinery.USE_PYQT5:
from PyQt5.QtWebEngineCore import *
from PyQt5.QtWebEngineWidgets import (
QWebEngineSettings,
@@ -25,7 +27,5 @@ if machinery.USE_PYQT5:
from PyQt5.QtWebEngine import PYQT_WEBENGINE_VERSION, PYQT_WEBENGINE_VERSION_STR
elif machinery.USE_PYQT6:
from PyQt6.QtWebEngineCore import *
-elif machinery.USE_PYSIDE6:
- from PySide6.QtWebEngineCore import *
else:
raise machinery.UnknownWrapper()
diff --git a/qutebrowser/qt/webenginewidgets.py b/qutebrowser/qt/webenginewidgets.py
index aed7babe9..922acf869 100644
--- a/qutebrowser/qt/webenginewidgets.py
+++ b/qutebrowser/qt/webenginewidgets.py
@@ -6,12 +6,12 @@
from qutebrowser.qt import machinery
-if machinery.USE_PYQT5:
+if machinery.USE_PYSIDE6:
+ from PySide6.QtWebEngineWidgets import *
+elif machinery.USE_PYQT5:
from PyQt5.QtWebEngineWidgets import *
elif machinery.USE_PYQT6:
from PyQt6.QtWebEngineWidgets import *
-elif machinery.USE_PYSIDE6:
- from PySide6.QtWebEngineWidgets import *
else:
raise machinery.UnknownWrapper()
diff --git a/qutebrowser/qt/webkit.py b/qutebrowser/qt/webkit.py
index 10250714e..d198b5dca 100644
--- a/qutebrowser/qt/webkit.py
+++ b/qutebrowser/qt/webkit.py
@@ -6,11 +6,11 @@
from qutebrowser.qt import machinery
-if machinery.USE_PYQT5:
+if machinery.USE_PYSIDE6:
+ raise machinery.Unavailable()
+elif machinery.USE_PYQT5:
from PyQt5.QtWebKit import *
elif machinery.USE_PYQT6:
raise machinery.Unavailable()
-elif machinery.USE_PYSIDE6:
- raise machinery.Unavailable()
else:
raise machinery.UnknownWrapper()
diff --git a/qutebrowser/qt/webkitwidgets.py b/qutebrowser/qt/webkitwidgets.py
index f8341e5cb..5a2df500e 100644
--- a/qutebrowser/qt/webkitwidgets.py
+++ b/qutebrowser/qt/webkitwidgets.py
@@ -6,11 +6,11 @@
from qutebrowser.qt import machinery
-if machinery.USE_PYQT5:
+if machinery.USE_PYSIDE6:
+ raise machinery.Unavailable()
+elif machinery.USE_PYQT5:
from PyQt5.QtWebKitWidgets import *
elif machinery.USE_PYQT6:
raise machinery.Unavailable()
-elif machinery.USE_PYSIDE6:
- raise machinery.Unavailable()
else:
raise machinery.UnknownWrapper()
diff --git a/qutebrowser/qt/widgets.py b/qutebrowser/qt/widgets.py
index d7ca04578..63e46c359 100644
--- a/qutebrowser/qt/widgets.py
+++ b/qutebrowser/qt/widgets.py
@@ -6,12 +6,14 @@
from qutebrowser.qt import machinery
-if machinery.USE_PYQT5:
+if machinery.USE_PYSIDE6:
+ from PySide6.QtWidgets import *
+elif machinery.USE_PYQT5:
from PyQt5.QtWidgets import *
elif machinery.USE_PYQT6:
from PyQt6.QtWidgets import *
-elif machinery.USE_PYSIDE6:
- from PySide6.QtWidgets import *
+else:
+ raise machinery.UnknownWrapper()
if machinery.IS_QT5:
del QFileSystemModel # moved to QtGui in Qt 6