From 3868e1e4a6d6a2cd25843e9d8fe0a10930e45621 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 4 Dec 2021 13:44:41 +1000 Subject: [PATCH] improve PyQt5.Qt compatibility - support 'from PyQt5 import Qt' case - alias it to aqt.qt modules instead of relying on getattr, so that 'from PyQt5.Qt import *' case works. --- qt/aqt/qt/qt5_compat.py | 6 +++--- qt/aqt/qt/qt5_qt_module.py | 16 ---------------- 2 files changed, 3 insertions(+), 19 deletions(-) delete mode 100644 qt/aqt/qt/qt5_qt_module.py diff --git a/qt/aqt/qt/qt5_compat.py b/qt/aqt/qt/qt5_compat.py index e3ef21daf..e940aa757 100644 --- a/qt/aqt/qt/qt5_compat.py +++ b/qt/aqt/qt/qt5_compat.py @@ -401,6 +401,6 @@ PyQt6.QtCore.QRegExp = PyQt6.QtCore.QRegularExpression # Mock the removed PyQt5.Qt module ########################################################################## -from . import qt5_qt_module - -sys.modules["PyQt5.Qt"] = qt5_qt_module +sys.modules["PyQt5.Qt"] = sys.modules["aqt.qt"] +# support 'from PyQt5 import Qt', as it's an alias to PyQt6 +PyQt6.Qt = sys.modules["aqt.qt"] diff --git a/qt/aqt/qt/qt5_qt_module.py b/qt/aqt/qt/qt5_qt_module.py deleted file mode 100644 index f606e8472..000000000 --- a/qt/aqt/qt/qt5_qt_module.py +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright: Ankitects Pty Ltd and contributors -# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html - -# pylint: skip-file - -""" -Compatibility shim for PyQt5.Qt -""" - -from typing import Any - - -def __getattr__(name: str) -> Any: - import aqt.qt - - return getattr(aqt.qt, name)