Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite enum access for scoped PyQt enums #5904

Closed
The-Compiler opened this issue Nov 23, 2020 · 5 comments
Closed

Rewrite enum access for scoped PyQt enums #5904

The-Compiler opened this issue Nov 23, 2020 · 5 comments
Labels
component: style / refactoring Issues related to coding styles or code that should be refactored. priority: 0 - high Issues which are currently the primary focus. qt: 6 Issues related to Qt 6.
Milestone

Comments

@The-Compiler
Copy link
Member

The-Compiler commented Nov 23, 2020

With sip v4.19.9 (around PyQt 5.11), there's a new way to access enums which makes them all scoped. With PyQt 6, this will be the only way Qt enums can be accessed.

Thus, enum access like QWebEngineSettings.AllowAllUnknownUrlSchemes should be rewritten to say QWebEngineSettings.UnknownUrlSchemePolicy.AllowAllUnknownUrlSchemes instead.

A rough way to search for them:

$ rg 'Q[A-Z][a-z][A-Za-z0-9]+\.[A-Z][a-z][A-Za-z0-9]+' 

here's a list of all of them (rg --no-filename 'Q[A-Z][a-z][A-Za-z0-9]+\.[A-Z][a-z][A-Za-z0-9]+' -o | sort | uniq):

QAbstractSocket.AddressInUseError
QAbstractSocket.SocketResourceError
QAbstractTextDocumentLayout.PaintContext
QClipboard.Clipboard
QClipboard.Selection
QColor.Cmyk
QColor.Hsl
QColor.Hsv
QColor.Rgb
QColor.Spec
QDataStream.ReadCorruptData
QDataStream.ReadPastEnd
QDataStream.Status
QDataStream.WriteFailed
QDialog.Accepted
QDialog.Rejected
QDialogButtonBox.AcceptRole
QDialogButtonBox.RejectRole
QDir.AllDirs
QDir.Drives
QDir.NoDot
QEvent.ChildAdded
QEvent.ChildRemoved
QEvent.FileOpen
QEvent.KeyPress
QEvent.KeyRelease
QEvent.MouseButtonPress
QEvent.MouseButtonRelease
QEvent.MouseMove
QEvent.ShortcutOverride
QEvent.Type
QEvent.User
QEvent.Wheel
QEventLoop.AllEvents
QEventLoop.ExcludeSocketNotifiers
QEventLoop.ExcludeUserInputEvents
QEventLoop.ProcessEventsFlags
QFileDevice.FileError
QFileDevice.OpenError
QFont.Bold
QFont.Cursive
QFont.Fantasy
QFont.Monospace
QFont.Normal
QFont.SansSerif
QFont.Serif
QFont.StyleHint
QFont.StyleItalic
QFont.StyleNormal
QFont.StyleOblique
QFont.TypeWriter
QFont.Weight
QFontDatabase.FixedFont
QFrame.Shadow
QFrame.Sunken
QHostAddress.LocalHost
QHostInfo.NoError
QIcon.Disabled
QIcon.Normal
QIcon.Off
QIcon.Selected
QItemSelectionModel.ClearAndSelect
QItemSelectionModel.Rows
QKeyEvent.KeyPress
QKeySequence.ExactMatch
QKeySequence.NoMatch
QKeySequence.PartialMatch
QKeySequence.SequenceMatch
QLibraryInfo.DataPath
QLibraryInfo.LibraryExecutablesPath
QLineEdit.Password
QListView.Adjust
QListView.LeftToRight
QLocalServer.UserAccessOption
QLocalSocket.ConnectionError
QLocalSocket.ConnectionRefusedError
QLocalSocket.PeerClosedError
QLocalSocket.ServerNotFoundError
QLocalSocket.UnconnectedState
QLocalSocket.UnknownSocketError
QMessageBox.Cancel
QMessageBox.Critical
QMessageBox.Information
QMessageBox.Warning
QMetaMethod.Signal
QNetworkAccessManager.GetOperation
QNetworkAccessManager.NotAccessible
QNetworkProxy.HostNameLookupCapability
QNetworkProxy.HttpProxy
QNetworkProxy.NoProxy
QNetworkProxy.Socks5Proxy
QNetworkReply.ContentAccessDenied
QNetworkReply.ContentNotFoundError
QNetworkReply.ContentOperationNotPermittedError
QNetworkReply.HostNotFoundError
QNetworkReply.InternalServerError
QNetworkReply.NoError
QNetworkReply.OperationCanceledError
QNetworkReply.ProtocolUnknownError
QNetworkReply.UnknownNetworkError
QNetworkReply.UnknownProxyError
QNetworkRequest.AlwaysNetwork
QNetworkRequest.CacheLoadControlAttribute
QNetworkRequest.CacheSaveControlAttribute
QNetworkRequest.ContentLengthHeader
QNetworkRequest.ContentTypeHeader
QNetworkRequest.HttpReasonPhraseAttribute
QNetworkRequest.HttpStatusCodeAttribute
QNetworkRequest.NoLessSafeRedirectPolicy
QNetworkRequest.RedirectPolicyAttribute
QNetworkRequest.RedirectionTargetAttribute
QNetworkRequest.UserAgentHeader
QPalette.Base
QPalette.Disabled
QPalette.Highlight
QPalette.HighlightedText
QPalette.Inactive
QPalette.Normal
QPalette.Text
QPalette.Window
QPalette.WindowText
QProcess.CrashExit
QProcess.Crashed
QProcess.ExitStatus
QProcess.NormalExit
QProcess.ProcessError
QProcess.Running
QProcess.SeparateChannels
QProcess.StandardError
QProcess.StandardOutput
QRegularExpression.CaseInsensitiveOption
QSettings.IniFormat
QSettings.NativeFormat
QSettings.UserScope
QSizePolicy.Expanding
QSizePolicy.Fixed
QSizePolicy.Ignored
QSizePolicy.Minimum
QSizePolicy.MinimumExpanding
QSizePolicy.Preferred
QSocketNotifier.Read
QSqlError.UnknownError
QSsl.TlsV1
QStandardPaths.AppDataLocation
QStandardPaths.AppLocalDataLocation
QStandardPaths.CacheLocation
QStandardPaths.ConfigLocation
QStandardPaths.DownloadLocation
QStandardPaths.RuntimeLocation
QStandardPaths.StandardLocation
QStandardPaths.TempLocation
QStyle.PrimitiveElement
QStyle.State
QStyleOptionViewItem.WrapText
QTabBar.SelectLeftTab
QTabBar.SelectPreviousTab
QTabBar.SelectRightTab
QTabWidget.East
QTabWidget.North
QTabWidget.South
QTabWidget.West
QTextCursor.End
QTextEdit.NoWrap
QTextOption.ManualWrap
QTextOption.WordWrap
QUrl.DecodeReserved
QUrl.EncodeFully
QUrl.EncodeUnicode
QUrl.FormattingOptions
QUrl.FullyDecoded
QUrl.FullyEncoded
QUrl.NormalizePathSegments
QUrl.PrettyDecoded
QUrl.RemoveFragment
QUrl.RemovePassword
QUrl.RemovePath
QUrl.RemoveQuery
QUrl.RemoveScheme
QUrl.RemoveUserInfo
QUrl.StrictMode
QUrl.StripTrailingSlash
QUrl.UrlFormattingOption
QValidator.Acceptable
QValidator.Invalid
QWebElement.ComputedStyle
QWebEngineCookieStore.FilterRequest
QWebEngineDownloadItem.DownloadCancelled
QWebEngineDownloadItem.DownloadCompleted
QWebEngineDownloadItem.DownloadInProgress
QWebEngineDownloadItem.DownloadInterrupted
QWebEngineDownloadItem.DownloadRequested
QWebEngineDownloadItem.DownloadState
QWebEngineDownloadItem.UnknownSaveFormat
QWebEnginePage.AbnormalTerminationStatus
QWebEnginePage.CrashedTerminationStatus
QWebEnginePage.DesktopAudioVideoCapture
QWebEnginePage.DesktopVideoCapture
QWebEnginePage.ErrorMessageLevel
QWebEnginePage.ExitFullScreen
QWebEnginePage.FindBackward
QWebEnginePage.FindCaseSensitively
QWebEnginePage.FindFlag
QWebEnginePage.FindFlags
QWebEnginePage.Geolocation
QWebEnginePage.InfoMessageLevel
QWebEnginePage.KilledTerminationStatus
QWebEnginePage.MediaAudioCapture
QWebEnginePage.MediaAudioVideoCapture
QWebEnginePage.MediaVideoCapture
QWebEnginePage.MouseLock
QWebEnginePage.NavigationType
QWebEnginePage.NavigationTypeBackForward
QWebEnginePage.NavigationTypeFormSubmitted
QWebEnginePage.NavigationTypeLinkClicked
QWebEnginePage.NavigationTypeOther
QWebEnginePage.NavigationTypeRedirect
QWebEnginePage.NavigationTypeReload
QWebEnginePage.NavigationTypeTyped
QWebEnginePage.NormalTerminationStatus
QWebEnginePage.Notifications
QWebEnginePage.PermissionDeniedByUser
QWebEnginePage.PermissionGrantedByUser
QWebEnginePage.Reload
QWebEnginePage.ReloadAndBypassCache
QWebEnginePage.RenderProcessTerminationStatus
QWebEnginePage.SavePage
QWebEnginePage.ViewSource
QWebEnginePage.WarningMessageLevel
QWebEnginePage.WebAction
QWebEnginePage.WebBrowserBackgroundTab
QWebEnginePage.WebBrowserTab
QWebEnginePage.WebBrowserWindow
QWebEnginePage.WebDialog
QWebEnginePage.WebWindowType
QWebEngineProfile.AllowPersistentCookies
QWebEngineProfile.NoPersistentCookies
QWebEngineScript.ApplicationWorld
QWebEngineScript.DocumentCreation
QWebEngineScript.DocumentReady
QWebEngineScript.MainWorld
QWebEngineScript.ScriptWorldId
QWebEngineScript.UserWorld
QWebEngineSettings.AllowAllUnknownUrlSchemes
QWebEngineSettings.AllowUnknownUrlSchemesFromUserInteraction
QWebEngineSettings.AutoLoadImages
QWebEngineSettings.CursiveFont
QWebEngineSettings.DefaultFixedFontSize
QWebEngineSettings.DefaultFontSize
QWebEngineSettings.DisallowUnknownUrlSchemes
QWebEngineSettings.DnsPrefetchEnabled
QWebEngineSettings.FantasyFont
QWebEngineSettings.FixedFont
QWebEngineSettings.FocusOnNavigationEnabled
QWebEngineSettings.FullScreenSupportEnabled
QWebEngineSettings.HyperlinkAuditingEnabled
QWebEngineSettings.JavascriptCanAccessClipboard
QWebEngineSettings.JavascriptCanOpenWindows
QWebEngineSettings.JavascriptEnabled
QWebEngineSettings.LinksIncludedInFocusChain
QWebEngineSettings.LocalContentCanAccessFileUrls
QWebEngineSettings.LocalContentCanAccessRemoteUrls
QWebEngineSettings.LocalStorageEnabled
QWebEngineSettings.MinimumFontSize
QWebEngineSettings.MinimumLogicalFontSize
QWebEngineSettings.PdfViewerEnabled
QWebEngineSettings.PlaybackRequiresUserGesture
QWebEngineSettings.PluginsEnabled
QWebEngineSettings.PrintElementBackgrounds
QWebEngineSettings.SansSerifFont
QWebEngineSettings.ScreenCaptureEnabled
QWebEngineSettings.ScrollAnimatorEnabled
QWebEngineSettings.SerifFont
QWebEngineSettings.SpatialNavigationEnabled
QWebEngineSettings.StandardFont
QWebEngineSettings.WebGLEnabled
QWebEngineUrlRequestInfo.ResourceType
QWebEngineUrlRequestInfo.ResourceTypeCspReport
QWebEngineUrlRequestInfo.ResourceTypeFavicon
QWebEngineUrlRequestInfo.ResourceTypeFontResource
QWebEngineUrlRequestInfo.ResourceTypeImage
QWebEngineUrlRequestInfo.ResourceTypeMainFrame
QWebEngineUrlRequestInfo.ResourceTypeMedia
QWebEngineUrlRequestInfo.ResourceTypeObject
QWebEngineUrlRequestInfo.ResourceTypePing
QWebEngineUrlRequestInfo.ResourceTypePluginResource
QWebEngineUrlRequestInfo.ResourceTypePrefetch
QWebEngineUrlRequestInfo.ResourceTypeScript
QWebEngineUrlRequestInfo.ResourceTypeServiceWorker
QWebEngineUrlRequestInfo.ResourceTypeSharedWorker
QWebEngineUrlRequestInfo.ResourceTypeStylesheet
QWebEngineUrlRequestInfo.ResourceTypeSubFrame
QWebEngineUrlRequestInfo.ResourceTypeSubResource
QWebEngineUrlRequestInfo.ResourceTypeUnknown
QWebEngineUrlRequestInfo.ResourceTypeWorker
QWebEngineUrlRequestInfo.ResourceTypeXhr
QWebEngineUrlRequestJob.RequestDenied
QWebEngineUrlRequestJob.RequestFailed
QWebEngineUrlRequestJob.UrlInvalid
QWebEngineUrlRequestJob.UrlNotFound
QWebEngineUrlScheme.LocalAccessAllowed
QWebEngineUrlScheme.LocalScheme
QWebPage.ChooseMultipleFilesExtension
QWebPage.ErrorPageExtension
QWebPage.ErrorPageExtensionOption
QWebPage.ErrorPageExtensionReturn
QWebPage.FindBackward
QWebPage.FindCaseSensitively
QWebPage.FindFlag
QWebPage.FindFlags
QWebPage.FindWrapsAroundDocument
QWebPage.Geolocation
QWebPage.HighlightAllOccurrences
QWebPage.MoveToEndOfBlock
QWebPage.MoveToEndOfDocument
QWebPage.MoveToEndOfLine
QWebPage.MoveToNextChar
QWebPage.MoveToNextLine
QWebPage.MoveToNextWord
QWebPage.MoveToPreviousChar
QWebPage.MoveToPreviousLine
QWebPage.MoveToPreviousWord
QWebPage.MoveToStartOfBlock
QWebPage.MoveToStartOfDocument
QWebPage.MoveToStartOfLine
QWebPage.NavigationType
QWebPage.NavigationTypeBackOrForward
QWebPage.NavigationTypeFormResubmitted
QWebPage.NavigationTypeFormSubmitted
QWebPage.NavigationTypeLinkClicked
QWebPage.NavigationTypeOther
QWebPage.NavigationTypeReload
QWebPage.Notifications
QWebPage.PermissionDeniedByUser
QWebPage.PermissionGrantedByUser
QWebPage.QtNetwork
QWebPage.Reload
QWebPage.ReloadAndBypassCache
QWebPage.SelectEndOfBlock
QWebPage.SelectEndOfDocument
QWebPage.SelectEndOfLine
QWebPage.SelectNextChar
QWebPage.SelectNextLine
QWebPage.SelectNextWord
QWebPage.SelectPreviousChar
QWebPage.SelectPreviousLine
QWebPage.SelectPreviousWord
QWebPage.SelectStartOfBlock
QWebPage.SelectStartOfDocument
QWebPage.SelectStartOfLine
QWebPage.ToggleVideoFullscreen
QWebPage.VisibilityStateHidden
QWebPage.VisibilityStateVisible
QWebPage.WebAction
QWebPage.WebKit
QWebPage.WebModalDialog
QWebSettings.AllowThirdPartyWithExistingCookies
QWebSettings.AlwaysAllowThirdPartyCookies
QWebSettings.AlwaysBlockThirdPartyCookies
QWebSettings.AutoLoadImages
QWebSettings.CaretBrowsingEnabled
QWebSettings.CursiveFont
QWebSettings.DefaultFixedFontSize
QWebSettings.DefaultFontSize
QWebSettings.DeveloperExtrasEnabled
QWebSettings.DnsPrefetchEnabled
QWebSettings.FantasyFont
QWebSettings.FixedFont
QWebSettings.FrameFlatteningEnabled
QWebSettings.HyperlinkAuditingEnabled
QWebSettings.JavascriptCanAccessClipboard
QWebSettings.JavascriptCanCloseWindows
QWebSettings.JavascriptCanOpenWindows
QWebSettings.JavascriptEnabled
QWebSettings.LinksIncludedInFocusChain
QWebSettings.LocalContentCanAccessFileUrls
QWebSettings.LocalContentCanAccessRemoteUrls
QWebSettings.LocalStorageEnabled
QWebSettings.MinimumFontSize
QWebSettings.MinimumLogicalFontSize
QWebSettings.OfflineStorageDatabaseEnabled
QWebSettings.OfflineWebApplicationCacheEnabled
QWebSettings.PluginsEnabled
QWebSettings.PrintElementBackgrounds
QWebSettings.PrivateBrowsingEnabled
QWebSettings.SansSerifFont
QWebSettings.ScrollAnimatorEnabled
QWebSettings.SerifFont
QWebSettings.SiteSpecificQuirksEnabled
QWebSettings.SpatialNavigationEnabled
QWebSettings.StandardFont
QWebSettings.WebGLEnabled
QWebSettings.ZoomTextOnly

(If you want to replicate that locally but don't have ripgrep, you could use something like grep -R --exclude-dir=.git --exclude-dir=.tox --exclude-dir='.venv*' --exclude-dir='.mypy_cache' --exclude='*.pyc' 'Q[A-Z][a-z][A-Za-z0-9]\+\.[A-Z][a-z][A-Za-z0-9]\+' . instead)

The scope to use for every one of those can be found out like this:

>>> from PyQt5.QtWebEngineWidgets import QWebEngineSettings
>>> type(QWebEngineSettings.AllowAllUnknownUrlSchemes).__name__
'UnknownUrlSchemePolicy'

so in theory it should be possible to solve this in a semi-automated way, by starting with the (rip)grep command above, writing a Python script to find the proper types to use (can use from PyQt5.Qt import * and from PyQt5.QtWebEngineWidgets import * to get access to most of those classes) and then generating something to feed to sed (or alternatively, implementing the search/replace in Python).

Marking this as "easy" as it's something that can be worked on without knowing much about qutebrowser internals. It will certainly require some manual work after writing such a script (for formatting adjustments and such), but that shouldn't be too much work. If you decide to work on this, please split it up into a couple of smaller PRs rather than one big one.

@The-Compiler The-Compiler added component: style / refactoring Issues related to coding styles or code that should be refactored. good first issue Issues which are likely to be a good fit for first-time contributors. priority: 0 - high Issues which are currently the primary focus. labels Nov 23, 2020
@The-Compiler The-Compiler added this to the v2.0.0 milestone Nov 23, 2020
@The-Compiler The-Compiler added qt: 6 Issues related to Qt 6. and removed good first issue Issues which are likely to be a good fit for first-time contributors. labels Nov 25, 2020
@The-Compiler
Copy link
Member Author

The-Compiler commented Dec 1, 2020

I ended up automating this which was easier than expected! First, a script which parses PyQt's .pyi files and writes a list of all enum members and their replacements:

import sys
import pathlib
from typed_ast import ast3


def add_parents(tree):
    for node in ast3.walk(tree):
        for child in ast.iter_child_nodes(node):
            child.parent = node


def find_enums(tree):
    for node in ast3.walk(tree):
        if not isinstance(node, ast3.Assign):
            continue
        if node.type_comment is None:
            continue
        if '.' not in node.type_comment:
            continue
        if not node.type_comment.startswith("'"):
            continue
        comment = node.type_comment.strip("'")
        mod, cls = comment.rsplit(".", maxsplit=1)
        assert len(node.targets) == 1
        name = node.targets[0].id
        yield (mod, cls, name)


def main():
    for filename in sys.argv[1:]:
        tree = ast3.parse(pathlib.Path(filename).read_text())
        for mod, cls, name in find_enums(tree):
            old = f"{mod}.{name}"
            new = f"{mod}.{cls}.{name}"
            print(f"{old} {new}")


if __name__ == '__main__':
    main()

(In theory, this should work with the builtin ast on Python 3.8 instead of typed_ast, but I always got back None for node.type_comment there...)

With the current PyQt and PyQtWebEngine modules, I get:
enums.txt (might only cover the Qt modules I have installed, not the entire PyQt - not sure!)

Second, a script which takes enums.txt and carries out the replacements:

import pathlib
import sys
import re

script_path = pathlib.Path(__file__).parent

replacements = []
with (script_path / 'enums.txt').open() as f:
    for line in f:
        orig, replacement = line.split()
        orig_re = re.compile(re.escape(orig) + r'(?=\W)')
        replacements.append((orig_re, replacement))


for filename in sys.argv[1:]:
    path = pathlib.Path(filename)
    if path.suffix != '.py':
        continue
    content = path.read_text()
    print(filename)
    for orig_re, replacement in replacements:
        content = orig_re.sub(replacement, content)
    path.write_text(content)

Which can get called via git ls-files | xargs python3 rewrite.py.

For testing, it should be possible to edit a custom PyQt build to remove the enum aliases - from a mailinglist post:

If you look in siplib.c of the source of the PyQt5.sip module, find add_lazy_container_attrs(). Remove the loop starting with the comment /* Do the unscoped enum members. */.


This leads to 127 files changed, 1338 insertions(+), 1338 deletions(-).

Not applying this at the moment because it can still wait a bit now that applying the actual change will be straightforward - I'd still like to wait for other (Py)Qt 6 changes before coming back to this again. Other issues to solve:

  • It'd also be nice to integrate it into misc_checks.py to avoid accidentally reintroducing the old names before we have Qt 6 on CI.
  • mypy with PyQt5-stubs isn't happy about this at all at the moment, showing things like:
qutebrowser/browser/shared.py:219: error: "Type[ComponentFormattingOption]" has
no attribute "FullyEncoded"  [attr-defined]
    ...String(QUrl.UrlFormattingOption.RemovePassword | QUrl.ComponentFormatt...
                                                        ^

@The-Compiler
Copy link
Member Author

The mypy stub changes are probably a bigger undertaking, so this won't be in v2.0.0.

@The-Compiler The-Compiler removed this from the v2.0.0 milestone Jan 8, 2021
mitya57 added a commit to retext-project/retext that referenced this issue Jan 12, 2021
As the PyQt5 changelog says:

v5.11 23rd June 2018
  [...]
  - Enum members are also visible as attributes of the enum in order to
    emulate the behaviour of Python enums.  The traditional use, where a member
    is visible at the same scope as the enum, is deprecated but will be
    supported throughout the life of PyQt5.

See also:
https://www.riverbankcomputing.com/static/Docs/PyQt5/gotchas.html#enums

Done using Florian Bruhin's excellent script:
qutebrowser/qutebrowser#5904 (comment)
The-Compiler added a commit that referenced this issue Aug 26, 2021
glutanimate added a commit to glutanimate/anki that referenced this issue Oct 20, 2021
Enums whose namespace moved with PyQt6 were determined using the tooling in qutebrowser/qutebrowser#5904

Relevant enums for the Anki add-on ecosystem were found by grepping through all AnkiWeb add-ons and a selection of GitHub-released add-ons.
dae pushed a commit to ankitects/anki that referenced this issue Oct 28, 2021
* Alias PyQt5 to PyQt6 on PyQt6 builds

Restores basic compatibility with PyQt5 add-ons

* Register QtCore early to work around sip error

* Monkey-patch unscoped enums that are in use by add-ons back in

Enums whose namespace moved with PyQt6 were determined using the tooling in qutebrowser/qutebrowser#5904

Relevant enums for the Anki add-on ecosystem were found by grepping through all AnkiWeb add-ons and a selection of GitHub-released add-ons.

* Add full Qt.Key namespace

Maintains compatibility with add-ons that allow specifying key bindings via Qt.Key enums

* Reintroduce PyQt6.Qt as an alias for QtCore.Qt

* Alias classes shifted from QtWidgets to QtGui

* Add missing enums

Adds ≈200 enums that were missed during the initial grep

* Map exec_ calls to exec

* Tweak section headers

* Fix QtWebEngineWidgets imports failing due to delayed import

Addesses: "QtWebEngineWidgets must be imported before a QCoreApplication instance is created"

* Register additional aliases for top-level Qt modules

Given how we have had to deal with side-effects when not registering other aliased imports ahead of time, it seems safer to also register the remaining few with sys.modules.

* Handle calls to deprecated PyQt resource API graciously

* Create QtWebEngineWidgets aliases for classes moved to QtWebEngineCore

* Alias QShortcut

* Restore QWebEnginePage.view()

* Alias sip to PyQt6.sip

* Alias QtCore.QRegExp to QtCore.QRegularExpression

* Restructure aqt.qt into package

Pre-requirement for aliasing the PyQt5.Qt namespace correctly.

Should hopefully also make it easier to keep an overview as Qt-compat-related modules were proliferating.

* Properly alias PyQt5.Qt

PyQt5.Qt used to serve as a common namespace for all Qt classes, not just QtCore.Qt.*

While this changes does not make all classes accessible via PyQt5.Qt, it does so for the most important Qt submodules, which should cover most add-on breakages.

* Simplify Qt resource system legacy handling

* Also alias PyQt6.Qt

Covers imports of the form `from PyQt5 import import Qt` (due to previous aliasing of PyQt5 to PyQt6)

* Add missing enums

Better approach to grepping through add-ons yielded additional hits

* Run formatters

* Satisfy pylint
foxxx0 pushed a commit to foxxx0/qutebrowser that referenced this issue Apr 3, 2022
foxxx0 pushed a commit to foxxx0/qutebrowser that referenced this issue Apr 3, 2022
foxxx0 pushed a commit to foxxx0/qutebrowser that referenced this issue Apr 3, 2022
@toofar toofar added this to the v3.0.0 milestone Apr 4, 2022
@The-Compiler
Copy link
Member Author

Mostly done in 0877fb0 (plus various follow-up commits).

Would still be nice to have this in misc_checks.py for the time being, to avoid regressions with merging PRs. I suppose once we have proper PyQt6 mypy running, we could drop it then.

@The-Compiler
Copy link
Member Author

We have mypy-pyqt6 running now, and it indeed detects this just fine.

@The-Compiler
Copy link
Member Author

Another note since I keep coming back to this thread for other projects: A git diff --word-diff-regex '[^[:space:].]+' makes this much easier to review (adding a literal . as word character, as opposed to the default definition of words being whitespace-separated).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: style / refactoring Issues related to coding styles or code that should be refactored. priority: 0 - high Issues which are currently the primary focus. qt: 6 Issues related to Qt 6.
Projects
None yet
Development

No branches or pull requests

2 participants