From 492e515c18db215e7f9bd9e3f8e84d09b9a67c11 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 28 Oct 2021 20:16:20 +1000 Subject: [PATCH] use aqt.qt to (partially) mock the old PyQt5 module We can't import the Qt5 libraries to do it - they are not usually available, and it will lead to crashes if both are imported at once. --- qt/aqt/qt/compat.py | 3 +-- qt/aqt/qt/qt5qt.py | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/qt/aqt/qt/compat.py b/qt/aqt/qt/compat.py index 40e4dbf48..dbd9a4ec7 100644 --- a/qt/aqt/qt/compat.py +++ b/qt/aqt/qt/compat.py @@ -1256,10 +1256,9 @@ QDBus.AutoDetect = QDBus.CallMode.AutoDetect QHostAddress.LocalHost = QHostAddress.SpecialAddress.LocalHost QPrinter.Millimeter = QPrinter.Unit.Millimeter -# Globally alias removed PyQt5.Qt to PyQt6.QtCore.Qt +# Mock the removed PyQt5.Qt module ########################################################################## from . import qt5qt sys.modules["PyQt5.Qt"] = qt5qt -sys.modules["PyQt6.Qt"] = qt5qt diff --git a/qt/aqt/qt/qt5qt.py b/qt/aqt/qt/qt5qt.py index a12392bf4..f606e8472 100644 --- a/qt/aqt/qt/qt5qt.py +++ b/qt/aqt/qt/qt5qt.py @@ -1,7 +1,6 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -# make sure not to optimize imports on this file # pylint: skip-file """ @@ -10,8 +9,8 @@ Compatibility shim for PyQt5.Qt from typing import Any -from .qt5 import * - def __getattr__(name: str) -> Any: - return getattr(Qt, name) # type: ignore + import aqt.qt + + return getattr(aqt.qt, name)