From 715153e4cc5ba4cdfa5c4ed480743fc9d29cd8c8 Mon Sep 17 00:00:00 2001 From: dalthviz Date: Mon, 17 Jan 2022 10:09:24 -0500 Subject: [PATCH 1/3] QtCharts: Add alias for backward compatibility with 1.x --- qtpy/__init__.py | 3 +++ qtpy/tests/test_qtcharts.py | 1 + 2 files changed, 4 insertions(+) diff --git a/qtpy/__init__.py b/qtpy/__init__.py index 33842484..9a4ba7a5 100644 --- a/qtpy/__init__.py +++ b/qtpy/__init__.py @@ -211,6 +211,9 @@ class PythonQtWarning(Warning): except (ImportError, PythonQtError): pass +# QtCharts backward compatibility with QtPy 1.x +from . import QtCharts +QtCharts.QtCharts = QtCharts def _warn_old_minor_version(name, old_version, min_version): """Warn if using a Qt or binding version no longer supported by QtPy.""" diff --git a/qtpy/tests/test_qtcharts.py b/qtpy/tests/test_qtcharts.py index 1c7ed425..0531b169 100644 --- a/qtpy/tests/test_qtcharts.py +++ b/qtpy/tests/test_qtcharts.py @@ -8,3 +8,4 @@ def test_qtcharts(): """Test the qtpy.QtCharts namespace""" from qtpy import QtCharts assert QtCharts.QChart is not None + assert QtCharts.QtCharts.QChart is not None From 3b6735d04f414958f52cec876583cfdc2cfe8a6c Mon Sep 17 00:00:00 2001 From: dalthviz Date: Tue, 18 Jan 2022 10:00:07 -0500 Subject: [PATCH 2/3] QtCharts: Catch errors when applying backward compat logic --- qtpy/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/qtpy/__init__.py b/qtpy/__init__.py index 9a4ba7a5..4cbee88f 100644 --- a/qtpy/__init__.py +++ b/qtpy/__init__.py @@ -211,9 +211,13 @@ class PythonQtWarning(Warning): except (ImportError, PythonQtError): pass -# QtCharts backward compatibility with QtPy 1.x -from . import QtCharts -QtCharts.QtCharts = QtCharts +try: + # QtCharts backward compatibility with QtPy 1.x + from . import QtCharts + QtCharts.QtCharts = QtCharts +except (ImportError, PythonQtError): + pass + def _warn_old_minor_version(name, old_version, min_version): """Warn if using a Qt or binding version no longer supported by QtPy.""" From c0f73b92f2d69ecc20449d8afa32e985e9fc947f Mon Sep 17 00:00:00 2001 From: dalthviz Date: Wed, 19 Jan 2022 10:14:28 -0500 Subject: [PATCH 3/3] QtCharts: Update handling for module layout --- qtpy/QtCharts.py | 4 ++++ qtpy/__init__.py | 7 ------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/qtpy/QtCharts.py b/qtpy/QtCharts.py index b041b0cd..164be471 100644 --- a/qtpy/QtCharts.py +++ b/qtpy/QtCharts.py @@ -12,6 +12,7 @@ if PYQT5: try: from PyQt5.QtChart import * + from PyQt5 import QtChart as QtCharts except ImportError as error: raise PythonQtError( 'The QtChart module was not found. ' @@ -20,6 +21,7 @@ elif PYQT6: try: from PyQt6.QtCharts import * + from PyQt6 import QtCharts except ImportError as error: raise PythonQtError( 'The QtCharts module was not found. ' @@ -27,7 +29,9 @@ ) from error elif PYSIDE6: from PySide6.QtCharts import * + from PySide6 import QtCharts elif PYSIDE2: + from PySide2.QtCharts import * # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026 import PySide2.QtCharts as __temp import inspect diff --git a/qtpy/__init__.py b/qtpy/__init__.py index 4cbee88f..33842484 100644 --- a/qtpy/__init__.py +++ b/qtpy/__init__.py @@ -211,13 +211,6 @@ class PythonQtWarning(Warning): except (ImportError, PythonQtError): pass -try: - # QtCharts backward compatibility with QtPy 1.x - from . import QtCharts - QtCharts.QtCharts = QtCharts -except (ImportError, PythonQtError): - pass - def _warn_old_minor_version(name, old_version, min_version): """Warn if using a Qt or binding version no longer supported by QtPy."""