aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2019-08-06 12:52:33 +0200
committerChristian Tismer <tismer@stackless.com>2019-08-06 18:53:13 +0200
commit21d948aa47dfe62b58286a31c729e76c9e3c13db (patch)
tree3edbc8b04de200ca2aea5656ff8d2f8d7212a601 /sources/pyside2
parent5838387e31987286ae836135ecd06326f0c7e1ba (diff)
PySide: Create a framework for deprecated functions
During development of the patch "Support Pointer Primitive Types by Arrays or Result Tuples" some functions in QtGui turned out to be removal candidates. The name "constData" should be deprecated in favor of the existing "data" function. Other implementation also do not have this. Instead of simply removing, we now create a surrogate function with the name "constData" in fure Python that gives a warning and calls the "data" function. This is now extracted into its own commit since the deprecation is a completely different and independent issue. The implementation does not do any extra imports in advance. and is easily extensible to more post-installation actions. Task-number: PYSIDE-795 Change-Id: I410c69a87d9f0df78f736991b2ee0a2747678911 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside2')
-rw-r--r--sources/pyside2/PySide2/CMakeLists.txt4
-rw-r--r--sources/pyside2/PySide2/support/__init__.py2
-rw-r--r--sources/pyside2/PySide2/support/deprecated.py80
-rw-r--r--sources/pyside2/tests/QtGui/CMakeLists.txt2
-rw-r--r--sources/pyside2/tests/QtGui/timed_app_and_patching_test.py (renamed from sources/pyside2/tests/QtGui/timed_app_test.py)19
5 files changed, 106 insertions, 1 deletions
diff --git a/sources/pyside2/PySide2/CMakeLists.txt b/sources/pyside2/PySide2/CMakeLists.txt
index d666751ea..e39db75a1 100644
--- a/sources/pyside2/PySide2/CMakeLists.txt
+++ b/sources/pyside2/PySide2/CMakeLists.txt
@@ -37,6 +37,10 @@ endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/__init__.py"
"${CMAKE_CURRENT_BINARY_DIR}/support/__init__.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/generate_pyi.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/support/generate_pyi.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/deprecated.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/support/deprecated.py" COPYONLY)
# now compile all modules.
file(READ "${CMAKE_CURRENT_BINARY_DIR}/pyside2_global.h" pyside2_global_contents)
diff --git a/sources/pyside2/PySide2/support/__init__.py b/sources/pyside2/PySide2/support/__init__.py
index dda01474d..8764fb5cb 100644
--- a/sources/pyside2/PySide2/support/__init__.py
+++ b/sources/pyside2/PySide2/support/__init__.py
@@ -38,3 +38,5 @@
#############################################################################
from shiboken2 import VoidPtr
+
+#eof
diff --git a/sources/pyside2/PySide2/support/deprecated.py b/sources/pyside2/PySide2/support/deprecated.py
new file mode 100644
index 000000000..8538826e4
--- /dev/null
+++ b/sources/pyside2/PySide2/support/deprecated.py
@@ -0,0 +1,80 @@
+# This Python file uses the following encoding: utf-8
+#############################################################################
+##
+## Copyright (C) 2019 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of Qt for Python.
+##
+## $QT_BEGIN_LICENSE:LGPL$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU Lesser General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU Lesser
+## General Public License version 3 as published by the Free Software
+## Foundation and appearing in the file LICENSE.LGPL3 included in the
+## packaging of this file. Please review the following information to
+## ensure the GNU Lesser General Public License version 3 requirements
+## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 2.0 or (at your option) the GNU General
+## Public license version 3 or any later version approved by the KDE Free
+## Qt Foundation. The licenses are as published by the Free Software
+## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-2.0.html and
+## https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+from __future__ import print_function, absolute_import
+
+"""
+deprecated.py
+
+This module contains deprecated things that are removed from the interface.
+They are implemented in Python again, together with a deprecation warning.
+
+Functions that are to be called for
+ PySide2.<module> must be named
+ fix_for_<module> .
+
+Note that this fixing code is run after all initializations, but before the
+import is finished. But that is no problem since the module is passed in.
+"""
+
+import warnings
+from textwrap import dedent
+
+
+class PySideDeprecationWarningRemovedInQt6(Warning):
+ pass
+
+
+def constData(self):
+ cls = self.__class__
+ name = cls.__name__
+ warnings.warn(dedent("""
+ {name}.constData is unpythonic and will be removed in Qt For Python 6.0 .
+ Please use {name}.data instead."""
+ .format(**locals())), PySideDeprecationWarningRemovedInQt6, stacklevel=2)
+ return cls.data(self)
+
+
+def fix_for_QtGui(QtGui):
+ for name, cls in QtGui.__dict__.items():
+ if name.startswith("QMatrix") and "data" in cls.__dict__:
+ cls.constData = constData
+
+# eof
diff --git a/sources/pyside2/tests/QtGui/CMakeLists.txt b/sources/pyside2/tests/QtGui/CMakeLists.txt
index 927e72468..172703ab9 100644
--- a/sources/pyside2/tests/QtGui/CMakeLists.txt
+++ b/sources/pyside2/tests/QtGui/CMakeLists.txt
@@ -46,4 +46,4 @@ PYSIDE_TEST(qtextdocumentwriter_test.py)
PYSIDE_TEST(qtextline_test.py)
PYSIDE_TEST(qtransform_test.py)
PYSIDE_TEST(repr_test.py)
-PYSIDE_TEST(timed_app_test.py)
+PYSIDE_TEST(timed_app_and_patching_test.py)
diff --git a/sources/pyside2/tests/QtGui/timed_app_test.py b/sources/pyside2/tests/QtGui/timed_app_and_patching_test.py
index dc0e7c4b0..014aeec1a 100644
--- a/sources/pyside2/tests/QtGui/timed_app_test.py
+++ b/sources/pyside2/tests/QtGui/timed_app_and_patching_test.py
@@ -29,6 +29,10 @@
import unittest
from helper import TimedQApplication
+from PySide2.support import deprecated
+from PySide2.support.signature import importhandler
+from PySide2 import QtGui
+
class TestTimedApp(TimedQApplication):
'''Simple test case for TimedQApplication'''
@@ -37,5 +41,20 @@ class TestTimedApp(TimedQApplication):
#Simple test of TimedQApplication
self.app.exec_()
+
+def fix_for_QtGui(QtGui):
+ QtGui.something = 42
+
+class TestPatchingFramework(unittest.TestCase):
+ """Simple test that verifies that deprecated.py works"""
+
+ deprecated.fix_for_QtGui = fix_for_QtGui
+
+ def test_patch_works(self):
+ something = "something"
+ self.assertFalse(hasattr(QtGui, something))
+ importhandler.finish_import(QtGui)
+ self.assertTrue(hasattr(QtGui, something))
+
if __name__ == '__main__':
unittest.main()