diff options
author | Christian Tismer <tismer@stackless.com> | 2020-10-27 11:34:32 +0100 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2020-10-27 21:13:20 +0000 |
commit | dcced0742f383b1932d0e56323387fbd8aeb4513 (patch) | |
tree | ccafffb6ffb68c9b8ddbeb1ade1ac5c8a1efa59b | |
parent | 844f1cc2541fe7213ebf2d72039ef28a04e200b4 (diff) |
remove traces of Python2 from Python code
It will be assumed that Python is always Python 3.
All checks for Python 2 are removed.
This is the first part of cleaning up the Python code.
We will then also clean the C code.
Task-number: PYSIDE-904
Change-Id: I06050a8c1a18a19583f551b61775833a91673f4e
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
13 files changed, 17 insertions, 69 deletions
diff --git a/sources/pyside2/tests/QtCore/classinfo_test.py b/sources/pyside2/tests/QtCore/classinfo_test.py index 634e8f350..d517b19c7 100644 --- a/sources/pyside2/tests/QtCore/classinfo_test.py +++ b/sources/pyside2/tests/QtCore/classinfo_test.py @@ -108,9 +108,4 @@ class TestClassInfo(unittest.TestCase): ClassInfo()(SubclassOfPythonQObjectSubclass) if __name__ == '__main__': - if sys.version_info[0] < 2: - sys.exit(0) - elif (sys.version_info[0] == 2) and (sys.version_info[1] <= 5): - sys.exit(0) - else: - unittest.main() + unittest.main() diff --git a/sources/pyside2/tests/QtCore/duck_punching_test.py b/sources/pyside2/tests/QtCore/duck_punching_test.py index 3450314dd..a735ecfa6 100644 --- a/sources/pyside2/tests/QtCore/duck_punching_test.py +++ b/sources/pyside2/tests/QtCore/duck_punching_test.py @@ -43,10 +43,7 @@ from PySide2.QtCore import QObject from helper.usesqcoreapplication import UsesQCoreApplication def MethodType(func, instance, instanceType): - if sys.version_info[0] == 3: - return types.MethodType(func, instance) - else: - return types.MethodType(func, instance, instanceType) + return types.MethodType(func, instance) class Duck(QObject): def __init__(self): diff --git a/sources/pyside2/tests/QtCore/qenum_test.py b/sources/pyside2/tests/QtCore/qenum_test.py index f99a893d9..f664087fd 100644 --- a/sources/pyside2/tests/QtCore/qenum_test.py +++ b/sources/pyside2/tests/QtCore/qenum_test.py @@ -137,11 +137,7 @@ class TestEnumPickling(unittest.TestCase): # Note: For Python 2, we would need quite strange patches. func = lambda: pickle.loads(pickle.dumps(Qt.Key)) - if sys.version_info[0] < 3: - with self.assertRaises(pickle.PicklingError): - func() - else: - func() + func() # PYSIDE-957: The QEnum macro diff --git a/sources/pyside2/tests/QtCore/qfile_test.py b/sources/pyside2/tests/QtCore/qfile_test.py index 57f9f4ee8..4617b1b2a 100644 --- a/sources/pyside2/tests/QtCore/qfile_test.py +++ b/sources/pyside2/tests/QtCore/qfile_test.py @@ -66,10 +66,7 @@ class GetCharTest(unittest.TestCase): try: memory = obj.map(0, 1) self.assertEqual(len(memory), 1) - if sys.version_info[0] >= 3: - self.assertEqual(memory[0], ord('a')) - else: - self.assertEqual(memory[0], bytes('a', "UTF-8")) + self.assertEqual(memory[0], ord('a')) # now memory points to wild bytes... :-) # uncommenting this must cause a segfault. # self.assertEqual(memory[0], 'a') diff --git a/sources/pyside2/tests/QtWidgets/qwidget_test.py b/sources/pyside2/tests/QtWidgets/qwidget_test.py index 5e94a8248..e2f7e5ed1 100644 --- a/sources/pyside2/tests/QtWidgets/qwidget_test.py +++ b/sources/pyside2/tests/QtWidgets/qwidget_test.py @@ -58,13 +58,6 @@ class QWidgetTest(UsesQApplication): def testInheritance(self): self.assertRaises(TypeError, QWidgetInherit) - if sys.version_info[0] < 3: - def testCallType_Issue_816(self): - thing = type(QWidget).__new__(type(QWidget), "", (), {}) - # PYSIDE-1286: This works now like in Python 3 - #self.assertEqual(repr(thing), "<class '__main__.'>") - self.assertEqual(repr(thing), "<class '__main__.ObjectType'>") - class QWidgetVisible(UsesQApplication): def testBasic(self): diff --git a/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py b/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py index 55953ad69..1998376d7 100644 --- a/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py +++ b/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py @@ -144,7 +144,7 @@ class MainTest(unittest.TestCase): #qPaintDevice = PySide2.QtGui.QPaintDevice() # NotImplementedError qTextDocument = PySide2.QtGui.QTextDocument() qTextFormat = PySide2.QtGui.QTextFormat() - quintptr = long(42) if sys.version_info[0] < 3 else 42 + quintptr = 42 qFont = PySide2.QtGui.QFont() qPalette = PySide2.QtGui.QPalette() except AttributeError: diff --git a/sources/pyside2/tests/pysidetest/property_python_test.py b/sources/pyside2/tests/pysidetest/property_python_test.py index 7df104525..443977c90 100644 --- a/sources/pyside2/tests/pysidetest/property_python_test.py +++ b/sources/pyside2/tests/pysidetest/property_python_test.py @@ -55,9 +55,8 @@ import sys import unittest has_test = False try: - if sys.version_info[0] >= 3: # This test has no support in Python 2 - from test import support - has_test = True + from test import support + has_test = True except ImportError: pass diff --git a/sources/pyside2/tests/registry/util.py b/sources/pyside2/tests/registry/util.py index 2a5ec322a..612ed253f 100644 --- a/sources/pyside2/tests/registry/util.py +++ b/sources/pyside2/tests/registry/util.py @@ -112,7 +112,7 @@ def linux_distribution(): distribution = distro.linux_distribution() except ImportError: # platform.linux_distribution() was removed in 3.8 - if sys.version_info[0] < 3 or sys.version_info[1] < 8: + if sys.version_info[:2] < (3, 8): import platform distribution = platform.linux_distribution() if distribution: diff --git a/sources/shiboken2/libshiboken/embed/embedding_generator.py b/sources/shiboken2/libshiboken/embed/embedding_generator.py index 15f63649b..8fb498008 100644 --- a/sources/shiboken2/libshiboken/embed/embedding_generator.py +++ b/sources/shiboken2/libshiboken/embed/embedding_generator.py @@ -89,7 +89,7 @@ def create_zipfile(limited_api): """ zip_name = "signature.zip" inc_name = "signature_inc.h" - flag = '-b' if sys.version_info >= (3,) else '' + flag = '-b' os.chdir(work_dir) # Remove all left-over py[co] and other files first, in case we use '--reuse-build'. @@ -105,10 +105,7 @@ def create_zipfile(limited_api): os.remove(fpath) # We copy every Python file into this dir, but only for the right version. # For testing in the source dir, we need to filter. - if sys.version_info[0] == 3: - ignore = "backport_inspect.py typing27.py".split() - else: - ignore = "".split() + ignore = [] utils.copydir(os.path.join(source_dir, "shiboken2", "shibokenmodule", "files.dir", "shibokensupport"), os.path.join(work_dir, "shibokensupport"), ignore=ignore, file_filter_function=lambda name, n2: name.endswith(".py")) diff --git a/sources/shiboken2/shibokenmodule/__init__.py.in b/sources/shiboken2/shibokenmodule/__init__.py.in index 6ba8929c9..f99011c7f 100644 --- a/sources/shiboken2/shibokenmodule/__init__.py.in +++ b/sources/shiboken2/shibokenmodule/__init__.py.in @@ -20,9 +20,7 @@ import re import tempfile import keyword import functools -if sys.version_info[0] == 3: - # PyInstaller seems to sometimes fail: - import typing +import typing from .shiboken2 import * diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py index 6ed4c0edd..8ddb75c19 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py @@ -130,10 +130,7 @@ def seterror_argument(args, func_name): return TypeError, msg def check_string_type(s): - if sys.version_info[0] == 3: - return isinstance(s, str) - else: - return isinstance(s, (str, unicode)) + return isinstance(s, str) def make_helptext(func): existing_doc = func.__doc__ diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py index 6cee54680..49c6439b7 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py @@ -153,27 +153,9 @@ def list_modules(message): orig_typing = True -if sys.version_info >= (3,): - import typing - import inspect - inspect.formatannotation = formatannotation -else: - tp_name = "typing" - if tp_name not in sys.modules: - orig_typing = False - from shibokensupport import typing27 as typing - sys.modules[tp_name] = typing - typing.__name__ = tp_name - else: - import typing - import inspect - namespace = inspect.__dict__ - from shibokensupport import backport_inspect as inspect - _doc = inspect.__doc__ - inspect.__dict__.update(namespace) - inspect.__doc__ += _doc - # force inspect to find all attributes. See "heuristic" in pydoc.py! - inspect.__all__ = list(x for x in dir(inspect) if not x.startswith("_")) +import typing +import inspect +inspect.formatannotation = formatannotation # Fix the module names in typing if possible. This is important since # the typing names should be I/O compatible, so that typing.Dict diff --git a/sources/shiboken2/tests/samplebinding/enum_test.py b/sources/shiboken2/tests/samplebinding/enum_test.py index 2ebc8d406..1289dada1 100644 --- a/sources/shiboken2/tests/samplebinding/enum_test.py +++ b/sources/shiboken2/tests/samplebinding/enum_test.py @@ -46,11 +46,8 @@ import sample from sample import SampleNamespace, ObjectType, Event def createTempFile(): - if sys.version_info >= (2, 6): - import tempfile - return tempfile.SpooledTemporaryFile(mode='rw') - else: - return os.tmpfile() + import tempfile + return tempfile.SpooledTemporaryFile(mode='rw') class EnumTest(unittest.TestCase): '''Test case for Python representation of C++ enums.''' |