diff options
63 files changed, 112 insertions, 496 deletions
diff --git a/docs/conf.py b/docs/conf.py index d7236c25..2263dc5a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - extensions = [ 'sphinx.ext.todo', 'sphinx.ext.intersphinx', diff --git a/examples/demo/demos/rotatedtext.py b/examples/demo/demos/rotatedtext.py index 8e4c2b73..4dac1897 100644 --- a/examples/demo/demos/rotatedtext.py +++ b/examples/demo/demos/rotatedtext.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# coding=utf-8 # -*- Mode: Python; py-indent-offset: 4 -*- # vim: tabstop=4 shiftwidth=4 expandtab # diff --git a/gi/__init__.py b/gi/__init__.py index bdfd5a99..34547903 100644 --- a/gi/__init__.py +++ b/gi/__init__.py @@ -18,8 +18,6 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 # USA -from __future__ import absolute_import - # support overrides in different directories than our gi module from pkgutil import extend_path __path__ = extend_path(__path__, __name__) @@ -44,7 +42,6 @@ from ._gi import _API from ._gi import Repository from ._gi import PyGIDeprecationWarning from ._gi import PyGIWarning -from ._compat import string_types _API = _API # pyflakes PyGIDeprecationWarning = PyGIDeprecationWarning @@ -111,7 +108,7 @@ def require_version(namespace, version): """ repository = Repository.get_default() - if not isinstance(version, string_types): + if not isinstance(version, str): raise ValueError('Namespace version needs to be a string.') if namespace in repository.get_loaded_namespaces(): diff --git a/gi/_compat.py b/gi/_compat.py deleted file mode 100644 index 00f5fbb3..00000000 --- a/gi/_compat.py +++ /dev/null @@ -1,56 +0,0 @@ -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, see <http://www.gnu.org/licenses/>. - -import sys - -PY2 = PY3 = False -if sys.version_info[0] == 2: - PY2 = True - - from StringIO import StringIO - StringIO - - from UserList import UserList - UserList - - long_ = eval("long") - integer_types = eval("(int, long)") - string_types = eval("(basestring,)") - text_type = eval("unicode") - - reload = eval("reload") - xrange = eval("xrange") - cmp = eval("cmp") - - exec("def reraise(tp, value, tb):\n raise tp, value, tb") -else: - PY3 = True - - from io import StringIO - StringIO - - from collections import UserList - UserList - - long_ = int - integer_types = (int,) - string_types = (str,) - text_type = str - - from importlib import reload - reload - xrange = range - cmp = lambda a, b: (a > b) - (a < b) - - def reraise(tp, value, tb): - raise tp(value).with_traceback(tb) diff --git a/gi/_option.py b/gi/_option.py index 9babb2ac..2fa54d89 100644 --- a/gi/_option.py +++ b/gi/_option.py @@ -32,7 +32,6 @@ import optparse from optparse import OptParseError, OptionError, OptionValueError, \ BadOptionError, OptionConflictError from .module import get_introspection_module -from ._compat import string_types from gi import _gi from gi._error import GError @@ -230,7 +229,7 @@ class OptionGroup(optparse.OptionGroup): def set_values_to_defaults(self): for option in self.option_list: default = self.defaults.get(option.dest) - if isinstance(default, string_types): + if isinstance(default, str): opt_str = option.get_opt_string() self.defaults[option.dest] = option.check_value( opt_str, default) @@ -310,7 +309,7 @@ class OptionParser(optparse.OptionParser): return context def add_option_group(self, *args, **kwargs): - if isinstance(args[0], string_types): + if isinstance(args[0], str): optparse.OptionParser.add_option_group(self, OptionGroup(self, *args, **kwargs)) return diff --git a/gi/_ossighelper.py b/gi/_ossighelper.py index 213f0965..fba24e6d 100644 --- a/gi/_ossighelper.py +++ b/gi/_ossighelper.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 Christoph Reiter # # This library is free software; you can redistribute it and/or @@ -17,7 +16,6 @@ from __future__ import print_function import os -import sys import socket import signal import threading @@ -63,8 +61,6 @@ def wakeup_on_signal(): shortly so that any registered Python signal handlers registered through signal.signal() can run. - Works on Windows but needs Python 3.5+. - In case the wrapped function is not called from the main thread it will be called as is and it will not wake up the default loop for signals. """ @@ -77,16 +73,6 @@ def wakeup_on_signal(): from gi.repository import GLib - # On Windows only Python 3.5+ supports passing sockets to set_wakeup_fd - set_wakeup_fd_supports_socket = ( - os.name != "nt" or sys.version_info[:2] >= (3, 5)) - # On Windows only Python 3 has an implementation of socketpair() - has_socketpair = hasattr(socket, "socketpair") - - if not has_socketpair or not set_wakeup_fd_supports_socket: - yield - return - read_socket, write_socket = socket.socketpair() with closing(read_socket), closing(write_socket): diff --git a/gi/_propertyhelper.py b/gi/_propertyhelper.py index 6f82ab6f..def34b22 100644 --- a/gi/_propertyhelper.py +++ b/gi/_propertyhelper.py @@ -18,7 +18,6 @@ # License along with this library; if not, see <http://www.gnu.org/licenses/>. from . import _gi -from ._compat import string_types, long_ from ._constants import \ TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR, \ TYPE_BOOLEAN, TYPE_INT, TYPE_UINT, TYPE_LONG, \ @@ -93,8 +92,6 @@ class Property(object): self.value = value """ _type_from_pytype_lookup = { - # Put long_ first in case long_ and int are the same so int clobbers long_ - long_: TYPE_LONG, int: TYPE_INT, bool: TYPE_BOOLEAN, float: TYPE_DOUBLE, @@ -152,11 +149,11 @@ class Property(object): self.default = self._get_default(default) self._check_default() - if not isinstance(nick, string_types): + if not isinstance(nick, str): raise TypeError("nick must be a string") self.nick = nick - if not isinstance(blurb, string_types): + if not isinstance(blurb, str): raise TypeError("blurb must be a string") self.blurb = blurb # Always clobber __doc__ with blurb even if blurb is empty because diff --git a/gi/importer.py b/gi/importer.py index e14d47be..32967974 100644 --- a/gi/importer.py +++ b/gi/importer.py @@ -21,7 +21,6 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 # USA -from __future__ import absolute_import import sys import warnings import importlib diff --git a/gi/meson.build b/gi/meson.build index c1afd689..4a049479 100644 --- a/gi/meson.build +++ b/gi/meson.build @@ -44,7 +44,6 @@ headers = [ install_headers(headers, subdir : 'pygobject-@0@'.format(platform_version)) python_sources = [ - '_compat.py', '_constants.py', 'docstring.py', '_error.py', diff --git a/gi/module.py b/gi/module.py index c5b030ab..f9e26bc2 100644 --- a/gi/module.py +++ b/gi/module.py @@ -20,16 +20,8 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 # USA -from __future__ import absolute_import - import importlib -try: - maketrans = ''.maketrans -except AttributeError: - # fallback for Python 2 - from string import maketrans - import gi from ._gi import \ @@ -155,7 +147,7 @@ class IntrospectionModule(object): # Don't use upper() here to avoid locale specific # identifier conversion (e. g. in Turkish 'i'.upper() == 'i') # see https://bugzilla.gnome.org/show_bug.cgi?id=649165 - ascii_upper_trans = maketrans( + ascii_upper_trans = ''.maketrans( 'abcdefgjhijklmnopqrstuvwxyz', 'ABCDEFGJHIJKLMNOPQRSTUVWXYZ') for value_info in info.get_values(): diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py index 81f214f0..95a3c1f3 100644 --- a/gi/overrides/GObject.py +++ b/gi/overrides/GObject.py @@ -29,8 +29,6 @@ import gi.module from gi.overrides import override, deprecated_attr from gi.repository import GLib from gi import PyGIDeprecationWarning -from gi._compat import PY2, text_type - from gi import _propertyhelper as propertyhelper from gi import _signalhelper as signalhelper from gi import _gi @@ -239,15 +237,8 @@ class Value(GObjectModule.Value): self.set_uchar(py_value) elif gtype == TYPE_STRING: if not isinstance(py_value, str) and py_value is not None: - if PY2: - if isinstance(py_value, text_type): - py_value = py_value.encode('UTF-8') - else: - raise TypeError("Expected string or unicode but got %s%s" % - (py_value, type(py_value))) - else: - raise TypeError("Expected string but got %s%s" % - (py_value, type(py_value))) + raise TypeError("Expected string but got %s%s" % + (py_value, type(py_value))) _gi._gvalue_set(self, py_value) elif gtype == TYPE_PARAM: self.set_param(py_value) diff --git a/gi/overrides/Gdk.py b/gi/overrides/Gdk.py index d77748e3..29e9dc55 100644 --- a/gi/overrides/Gdk.py +++ b/gi/overrides/Gdk.py @@ -295,9 +295,6 @@ if GDK2 or GDK3: for method_info in Gdk.Event.__info__.get_methods(): name = method_info.get_name() event_method = getattr(Gdk.Event, name) - # python2 we need to use the __func__ attr to avoid internal - # instance checks - event_method = getattr(event_method, '__func__', event_method) # use the _gsuccess_mask decorator if this method is whitelisted if name in gsuccess_mask_funcs: diff --git a/gi/overrides/Gio.py b/gi/overrides/Gio.py index eafbae52..5cc12a6c 100644 --- a/gi/overrides/Gio.py +++ b/gi/overrides/Gio.py @@ -23,7 +23,6 @@ import warnings from .._ossighelper import wakeup_on_signal, register_sigint_fallback from ..overrides import override, deprecated_init from ..module import get_introspection_module -from .._compat import xrange from gi._gi import pygobject_new_full from gi import PyGIWarning @@ -427,7 +426,7 @@ class ListModel(Gio.ListModel): def __getitem__(self, key): if isinstance(key, slice): - return [self.get_item(i) for i in xrange(*key.indices(len(self)))] + return [self.get_item(i) for i in range(*key.indices(len(self)))] elif isinstance(key, int): if key < 0: key += len(self) @@ -454,7 +453,7 @@ class ListModel(Gio.ListModel): return self.get_n_items() def __iter__(self): - for i in xrange(len(self)): + for i in range(len(self)): yield self.get_item(i) @@ -504,7 +503,7 @@ class ListStore(Gio.ListStore): elif step == -1: _list_store_splice(self, stop + 1, max(start - stop, 0), []) else: - for i in sorted(xrange(start, stop, step), reverse=True): + for i in sorted(range(start, stop, step), reverse=True): self.remove(i) elif isinstance(key, int): if key < 0: @@ -531,7 +530,7 @@ class ListStore(Gio.ListStore): _list_store_splice( self, start, max(stop - start, 0), valuelist) else: - indices = list(xrange(start, stop, step)) + indices = list(range(start, stop, step)) if len(indices) != len(valuelist): raise ValueError diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py index d1ed83da..35d5fcb9 100644 --- a/gi/overrides/Gtk.py +++ b/gi/overrides/Gtk.py @@ -21,18 +21,13 @@ import sys import warnings - -if sys.version_info[0] == 2: - import collections as abc -else: - from collections import abc +from collections import abc from gi.repository import GObject from .._ossighelper import wakeup_on_signal, register_sigint_fallback from .._gtktemplate import Template from ..overrides import override, strip_boolean_result, deprecated_init from ..module import get_introspection_module -from .._compat import string_types from gi import PyGIDeprecationWarning @@ -409,7 +404,7 @@ if Gtk._version in ("2.0", "3.0"): class UIManager(Gtk.UIManager): def add_ui_from_string(self, buffer): - if not isinstance(buffer, string_types): + if not isinstance(buffer, str): raise TypeError('buffer must be a string') length = _get_utf8_length(buffer) @@ -463,7 +458,7 @@ if Gtk._version in ("2.0", "3.0"): def _get_utf8_length(string): - assert isinstance(string, string_types) + assert isinstance(string, str) if not isinstance(string, bytes): string = string.encode("utf-8") return len(string) @@ -485,7 +480,7 @@ class Builder(Gtk.Builder): self.connect_signals_full(_builder_connect_callback, obj_or_map) def add_from_string(self, buffer): - if not isinstance(buffer, string_types): + if not isinstance(buffer, str): raise TypeError('buffer must be a string') length = _get_utf8_length(buffer) @@ -493,7 +488,7 @@ class Builder(Gtk.Builder): return Gtk.Builder.add_from_string(self, buffer, length) def add_objects_from_string(self, buffer, object_ids): - if not isinstance(buffer, string_types): + if not isinstance(buffer, str): raise TypeError('buffer must be a string') length = _get_utf8_length(buffer) @@ -759,7 +754,7 @@ class TextBuffer(Gtk.TextBuffer): Gtk.TextBuffer.set_text(self, text, length) def insert(self, iter, text, length=-1): - if not isinstance(text, string_types): + if not isinstance(text, str): raise TypeError('text must be a string, not %s' % type(text)) Gtk.TextBuffer.insert(self, iter, text, length) @@ -788,7 +783,7 @@ class TextBuffer(Gtk.TextBuffer): self.insert_with_tags(iter, text, *tag_objs) def insert_at_cursor(self, text, length=-1): - if not isinstance(text, string_types): + if not isinstance(text, str): raise TypeError('text must be a string, not %s' % type(text)) Gtk.TextBuffer.insert_at_cursor(self, text, length) @@ -1209,7 +1204,7 @@ class TreePath(Gtk.TreePath): def __new__(cls, path=0): if isinstance(path, int): path = str(path) - elif not isinstance(path, string_types): + elif not isinstance(path, str): path = ":".join(str(val) for val in path) if len(path) == 0: diff --git a/gi/pygtkcompat.py b/gi/pygtkcompat.py index 4a9c4bea..364fb6c2 100644 --- a/gi/pygtkcompat.py +++ b/gi/pygtkcompat.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import import warnings from gi import PyGIDeprecationWarning diff --git a/gi/repository/__init__.py b/gi/repository/__init__.py index 5c5552ac..640fc8e7 100644 --- a/gi/repository/__init__.py +++ b/gi/repository/__init__.py @@ -18,8 +18,6 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 # USA -from __future__ import absolute_import - import sys from ..importer import DynamicImporter diff --git a/gi/types.py b/gi/types.py index 47ed18a5..92059363 100644 --- a/gi/types.py +++ b/gi/types.py @@ -20,9 +20,6 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 # USA -from __future__ import absolute_import - -import warnings import re from ._constants import TYPE_INVALID @@ -290,19 +287,7 @@ def mro(C): # in __mro__ at each point. Therefore at this point we know that # we already have our base class MRO's available to us, there is # no need for us to (re)calculate them. - if hasattr(base, '__mro__'): - bases_of_subclasses += [list(base.__mro__)] - else: - warnings.warn('Mixin class %s is an old style class, please ' - 'update this to derive from "object".' % base, - RuntimeWarning) - # For old-style classes (Python2 only), the MRO is not - # easily accessible. As we do need it here, we calculate - # it via recursion, according to the C3 algorithm. Using C3 - # for old style classes deviates from Python's own behaviour, - # but visible effects here would be a corner case triggered by - # questionable design. - bases_of_subclasses += [mro(base)] + bases_of_subclasses += [list(base.__mro__)] bases_of_subclasses += [list(C.__bases__)] while bases_of_subclasses: diff --git a/pygtkcompat/pygtkcompat.py b/pygtkcompat/pygtkcompat.py index c9711c68..966b67b6 100644 --- a/pygtkcompat/pygtkcompat.py +++ b/pygtkcompat/pygtkcompat.py @@ -34,10 +34,10 @@ a well behaved PyGTK application mostly unmodified on top of PyGI. import sys import warnings +from collections import UserList import gi from gi.repository import GObject -from gi import _compat _patches = [] @@ -149,10 +149,6 @@ def _disable_all(): sys.modules[name] = old_value del _module_patches[:] - _compat.reload(sys) - if _compat.PY2: - sys.setdefaultencoding('ascii') - def enable_gtk(version='3.0'): if _check_enabled("gtk", version): @@ -161,11 +157,6 @@ def enable_gtk(version='3.0'): if version == "4.0": raise ValueError("version 4.0 not supported") - # set the default encoding like PyGTK - _compat.reload(sys) - if _compat.PY2: - sys.setdefaultencoding('utf-8') - # atk gi.require_version('Atk', '1.0') from gi.repository import Atk @@ -429,11 +420,11 @@ def enable_gtk(version='3.0'): orig_size_request = Gtk.Widget.size_request def size_request(widget): - class SizeRequest(_compat.UserList): + class SizeRequest(UserList): def __init__(self, req): self.height = req.height self.width = req.width - _compat.UserList.__init__(self, [self.width, self.height]) + UserList.__init__(self, [self.width, self.height]) return SizeRequest(orig_size_request(widget)) _patch(Gtk.Widget, "size_request", size_request) _patch(Gtk.Widget, "hide_all", Gtk.Widget.hide) @@ -217,11 +217,7 @@ def pkg_config_version_check(pkg_name, version): def pkg_config_parse(opt, pkg_name): ret = _run_pkg_config_or_exit(pkg_name, [opt, pkg_name]) - - if sys.version_info[0] == 3: - output = ret.decode() - else: - output = ret + output = ret.decode() opt = opt[-2:] return [x.lstrip(opt) for x in output.split()] @@ -874,23 +870,13 @@ def get_pycairo_include_dir(): location = os.path.dirname(os.path.abspath(cairo.__path__[0])) log.info("pycairo: found %r" % location) - def samefile(src, dst): - # Python 2 on Windows doesn't have os.path.samefile, so we have to - # provide a fallback - if hasattr(os.path, "samefile"): - return os.path.samefile(src, dst) - os.stat(src) - os.stat(dst) - return (os.path.normcase(os.path.abspath(src)) == - os.path.normcase(os.path.abspath(dst))) - def get_sys_path(location, name): # Returns the sysconfig path for a distribution, or None for scheme in sysconfig.get_scheme_names(): for path_type in ["platlib", "purelib"]: path = sysconfig.get_path(path_type, scheme) try: - if samefile(path, location): + if os.path.samefile(path, location): return sysconfig.get_path(name, scheme) except EnvironmentError: pass @@ -998,11 +984,6 @@ def add_ext_compiler_flags(ext, compiler, _cache={}): "-Wwrite-strings", ] - if sys.version_info[0] == 2: - args += [ - "-Wdeclaration-after-statement", - ] - args += [ "-Wno-incompatible-pointer-types-discards-qualifiers", "-Wno-missing-field-initializers", diff --git a/tests/__init__.py b/tests/__init__.py index c5f02c31..44068d2c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import os import sys import unittest @@ -34,12 +32,8 @@ sys.meta_path.insert(0, GIImport()) def init_test_environ(): # this was renamed in Python 3, provide backwards compatible name - if sys.version_info[:2] == (2, 7): - unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp - - if sys.version_info[0] == 3: - unittest.TestCase.assertRegexpMatches = unittest.TestCase.assertRegex - unittest.TestCase.assertRaisesRegexp = unittest.TestCase.assertRaisesRegex + unittest.TestCase.assertRegexpMatches = unittest.TestCase.assertRegex + unittest.TestCase.assertRaisesRegexp = unittest.TestCase.assertRaisesRegex def dbus_launch_session(): if os.name == "nt" or sys.platform == "darwin": @@ -52,8 +46,7 @@ def init_test_environ(): except (subprocess.CalledProcessError, OSError): return (-1, "") else: - if sys.version_info[0] == 3: - out = out.decode("utf-8") + out = out.decode("utf-8") addr, pid = out.splitlines() return int(pid), addr diff --git a/tests/conftest.py b/tests/conftest.py index 820210ce..254a7217 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,13 +1,7 @@ -# -*- coding: utf-8 -*- - -from __future__ import absolute_import - import sys import pytest -from gi._compat import reraise - @pytest.hookimpl(hookwrapper=True, tryfirst=True) def pytest_runtest_call(item): @@ -28,4 +22,5 @@ def pytest_runtest_call(item): finally: sys.excepthook = orig_excepthook if exceptions: - reraise(*exceptions[0]) + tp, value, tb = exceptions[0] + raise tp(value).with_traceback(tb) diff --git a/tests/helper.py b/tests/helper.py index 1485ec3d..bed51e8d 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import contextlib import unittest import inspect @@ -7,11 +5,11 @@ import warnings import functools import sys from collections import namedtuple +from io import StringIO import gi from gi import PyGIDeprecationWarning from gi.repository import GLib -from gi._compat import StringIO ExceptionInfo = namedtuple("ExceptionInfo", ["type", "value", "traceback"]) diff --git a/tests/runtests.py b/tests/runtests.py index c05702a2..721b5d80 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -1,8 +1,6 @@ #!/usr/bin/env python # -*- Mode: Python -*- -from __future__ import absolute_import - import os import sys diff --git a/tests/test_atoms.py b/tests/test_atoms.py index 26d5c43a..a74db38c 100644 --- a/tests/test_atoms.py +++ b/tests/test_atoms.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import os import unittest diff --git a/tests/test_cairo.py b/tests/test_cairo.py index 37a6ac38..d73037e3 100644 --- a/tests/test_cairo.py +++ b/tests/test_cairo.py @@ -1,9 +1,6 @@ # -*- Mode: Python; py-indent-offset: 4 -*- -# coding=utf-8 # vim: tabstop=4 shiftwidth=4 expandtab -from __future__ import absolute_import - import unittest import pytest diff --git a/tests/test_docstring.py b/tests/test_docstring.py index adee174c..29b7e5ef 100644 --- a/tests/test_docstring.py +++ b/tests/test_docstring.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import unittest import gi.docstring diff --git a/tests/test_error.py b/tests/test_error.py index a15c7d33..6bcad38c 100644 --- a/tests/test_error.py +++ b/tests/test_error.py @@ -22,8 +22,6 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 # USA -from __future__ import absolute_import - import unittest import pickle diff --git a/tests/test_everything.py b/tests/test_everything.py index 68e87652..ba1b0629 100644 --- a/tests/test_everything.py +++ b/tests/test_everything.py @@ -1,9 +1,6 @@ # -*- Mode: Python; py-indent-offset: 4 -*- -# coding=utf-8 # vim: tabstop=4 shiftwidth=4 expandtab -from __future__ import absolute_import - import unittest import traceback import ctypes @@ -21,7 +18,6 @@ from gi.repository import Regress as Everything from gi.repository import GObject from gi.repository import GLib from gi.repository import Gio -from gi._compat import PY3, PY2 try: from gi.repository import Gtk @@ -32,9 +28,7 @@ except: from .helper import capture_exceptions -const_str = b'const \xe2\x99\xa5 utf8' -if PY3: - const_str = const_str.decode('UTF-8') +const_str = b'const \xe2\x99\xa5 utf8'.decode('UTF-8') noconst_str = 'non' + const_str @@ -366,11 +360,7 @@ class TestEverything(unittest.TestCase): def test_unichar(self): self.assertEqual("c", Everything.test_unichar("c")) - if PY2: - self.assertEqual(b"\xe2\x99\xa5", Everything.test_unichar(u"♥")) - self.assertEqual(b"\xe2\x99\xa5", Everything.test_unichar(b"\xe2\x99\xa5")) - else: - self.assertEqual(u"♥", Everything.test_unichar(u"♥")) + self.assertEqual(u"♥", Everything.test_unichar(u"♥")) self.assertRaises(TypeError, Everything.test_unichar, "") self.assertRaises(TypeError, Everything.test_unichar, "morethanonechar") @@ -444,7 +434,7 @@ class TestEverything(unittest.TestCase): self.assertEqual(Everything.test_utf8_inout(const_str), noconst_str) def test_filename_return(self): - if PY3 and os.name != "nt": + if os.name != "nt": result = [os.fsdecode(b'\xc3\xa5\xc3\xa4\xc3\xb6'), '/etc/fstab'] else: result = ['åäö', '/etc/fstab'] @@ -596,8 +586,7 @@ class TestEverything(unittest.TestCase): self.assertEqual(Everything.test_array_int_inout([]), []) def test_array_gint8_in(self): - if PY3: - self.assertEqual(Everything.test_array_gint8_in(b'\x01\x03\x05'), 9) + self.assertEqual(Everything.test_array_gint8_in(b'\x01\x03\x05'), 9) self.assertEqual(Everything.test_array_gint8_in([1, 3, 5, -50]), -41) def test_array_gint16_in(self): diff --git a/tests/test_fields.py b/tests/test_fields.py index 0181d288..b9a06e2f 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1,7 +1,4 @@ # -*- Mode: Python; py-indent-offset: 4 -*- -# coding=utf-8 - -from __future__ import absolute_import import math import unittest diff --git a/tests/test_gdbus.py b/tests/test_gdbus.py index 6e38abe3..6c9afb07 100644 --- a/tests/test_gdbus.py +++ b/tests/test_gdbus.py @@ -1,8 +1,6 @@ # -*- Mode: Python; py-indent-offset: 4 -*- # vim: tabstop=4 shiftwidth=4 expandtab -from __future__ import absolute_import - import unittest from gi.repository import GLib diff --git a/tests/test_generictreemodel.py b/tests/test_generictreemodel.py index acb6028c..ab315798 100644 --- a/tests/test_generictreemodel.py +++ b/tests/test_generictreemodel.py @@ -17,8 +17,6 @@ # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, see <http://www.gnu.org/licenses/>. -from __future__ import absolute_import - # system import gc import sys diff --git a/tests/test_gi.py b/tests/test_gi.py index 61ad4f18..2cabe021 100644 --- a/tests/test_gi.py +++ b/tests/test_gi.py @@ -1,9 +1,6 @@ # -*- Mode: Python; py-indent-offset: 4 -*- -# coding=utf-8 # vim: tabstop=4 shiftwidth=4 expandtab -from __future__ import absolute_import - import sys import unittest @@ -22,7 +19,6 @@ from gi import PyGIWarning from gi import PyGIDeprecationWarning from gi.repository import GObject, GLib, Gio from gi.repository import GIMarshallingTests -from gi._compat import PY2, PY3 import pytest from .helper import capture_exceptions, capture_output @@ -681,21 +677,14 @@ class TestUtf8(unittest.TestCase): def test_extra_utf8_full_return_invalid(self): with pytest.raises(UnicodeDecodeError): - value = GIMarshallingTests.extra_utf8_full_return_invalid() - if PY2: - value.decode("utf-8") + GIMarshallingTests.extra_utf8_full_return_invalid() def test_extra_utf8_full_out_invalid(self): with pytest.raises(UnicodeDecodeError): - value = GIMarshallingTests.extra_utf8_full_out_invalid() - if PY2: - value.decode("utf-8") + GIMarshallingTests.extra_utf8_full_out_invalid() def test_utf8_none_in(self): GIMarshallingTests.utf8_none_in(CONSTANT_UTF8) - if PY2: - GIMarshallingTests.utf8_none_in(CONSTANT_UTF8.decode("utf-8")) - self.assertRaises(TypeError, GIMarshallingTests.utf8_none_in, 42) self.assertRaises(TypeError, GIMarshallingTests.utf8_none_in, None) @@ -784,22 +773,6 @@ class TestFilename(unittest.TestCase): (ValueError, TypeError), GIMarshallingTests.filename_copy, u"foo\x00") - def test_as_is_py2(self): - if not PY2: - return - - values = [ - b"foo", - b"\xff\xff", - b"\xc3\xb6\xc3\xa4\xc3\xbc", - b"\xed\xa0\xbd", - b"\xf0\x90\x80\x81", - ] - - for v in values: - self.assertEqual(GIMarshallingTests.filename_copy(v), v) - self.assertEqual(GIMarshallingTests.filename_to_glib_repr(v), v) - def test_win32_surrogates(self): if os.name != "nt": return @@ -807,15 +780,10 @@ class TestFilename(unittest.TestCase): copy = GIMarshallingTests.filename_copy glib_repr = GIMarshallingTests.filename_to_glib_repr - if PY3: - self.assertEqual(copy(u"\ud83d"), u"\ud83d") - self.assertEqual(copy(u"\x61\uDC00"), u"\x61\uDC00") - self.assertEqual(copy(u"\uD800\uDC01"), u"\U00010001") - self.assertEqual(copy(u"\uD83D\x20\uDCA9"), u"\uD83D\x20\uDCA9") - else: - self.assertEqual(copy(u"\ud83d"), u"\ud83d".encode("utf-8")) - self.assertEqual(copy(u"\uD800\uDC01").decode("utf-8"), - u"\U00010001") + self.assertEqual(copy(u"\ud83d"), u"\ud83d") + self.assertEqual(copy(u"\x61\uDC00"), u"\x61\uDC00") + self.assertEqual(copy(u"\uD800\uDC01"), u"\U00010001") + self.assertEqual(copy(u"\uD83D\x20\uDCA9"), u"\uD83D\x20\uDCA9") self.assertEqual(glib_repr(u"\ud83d"), b"\xed\xa0\xbd") self.assertEqual(glib_repr(u"\uD800\uDC01"), b"\xf0\x90\x80\x81") @@ -830,7 +798,7 @@ class TestFilename(unittest.TestCase): self.assertEqual(glib_repr(u"\uDC00"), b"\xED\xB0\x80") def test_win32_bytes_py3(self): - if not (os.name == "nt" and PY3): + if not (os.name == "nt"): return values = [ @@ -855,39 +823,27 @@ class TestFilename(unittest.TestCase): copy = GIMarshallingTests.filename_copy glib_repr = GIMarshallingTests.filename_to_glib_repr - if PY3: - try: - os.fsdecode(b"\xff\xfe") - except UnicodeDecodeError: - self.assertRaises(UnicodeDecodeError, copy, b"\xff\xfe") - else: - str_path = copy(b"\xff\xfe") - self.assertTrue(isinstance(str_path, str)) - self.assertEqual(str_path, os.fsdecode(b"\xff\xfe")) - self.assertEqual(copy(str_path), str_path) - self.assertEqual(glib_repr(b"\xff\xfe"), b"\xff\xfe") - self.assertEqual(glib_repr(str_path), b"\xff\xfe") - - # if getfilesystemencoding is ASCII, then we should fail like - # os.fsencode - try: - byte_path = os.fsencode(u"ä") - except UnicodeEncodeError: - self.assertRaises(UnicodeEncodeError, copy, u"ä") - else: - self.assertEqual(copy(u"ä"), u"ä") - self.assertEqual(glib_repr(u"ä"), byte_path) + try: + os.fsdecode(b"\xff\xfe") + except UnicodeDecodeError: + self.assertRaises(UnicodeDecodeError, copy, b"\xff\xfe") else: - self.assertTrue(isinstance(copy(b"\xff\xfe"), bytes)) - self.assertEqual(copy(u"foo"), b"foo") - self.assertTrue(isinstance(copy(u"foo"), bytes)) - try: - byte_path = u"ä".encode(sys.getfilesystemencoding()) - except UnicodeEncodeError: - self.assertRaises(UnicodeEncodeError, copy, u"ä") - else: - self.assertEqual(copy(u"ä"), byte_path) - self.assertEqual(glib_repr(u"ä"), byte_path) + str_path = copy(b"\xff\xfe") + self.assertTrue(isinstance(str_path, str)) + self.assertEqual(str_path, os.fsdecode(b"\xff\xfe")) + self.assertEqual(copy(str_path), str_path) + self.assertEqual(glib_repr(b"\xff\xfe"), b"\xff\xfe") + self.assertEqual(glib_repr(str_path), b"\xff\xfe") + + # if getfilesystemencoding is ASCII, then we should fail like + # os.fsencode + try: + byte_path = os.fsencode(u"ä") + except UnicodeEncodeError: + self.assertRaises(UnicodeEncodeError, copy, u"ä") + else: + self.assertEqual(copy(u"ä"), u"ä") + self.assertEqual(glib_repr(u"ä"), byte_path) @unittest.skip("glib can't handle non-unicode paths") def test_win32_surrogates_exists(self): @@ -902,15 +858,15 @@ class TestFilename(unittest.TestCase): def test_path_exists_various_types(self): wd = self.workdir - wdb = os.fsencode(wd) if PY3 else wd + wdb = os.fsencode(wd) paths = [(wdb, b"foo-1"), (wd, u"foo-2"), (wd, u"öäü-3")] - if PY3: - try: - paths.append((wd, os.fsdecode(b"\xff\xfe-4"))) - except UnicodeDecodeError: - # depends on the code page - pass + + try: + paths.append((wd, os.fsdecode(b"\xff\xfe-4"))) + except UnicodeDecodeError: + # depends on the code page + pass if os.name != "nt": paths.append((wdb, b"\xff\xfe-5")) @@ -961,10 +917,7 @@ class TestArray(unittest.TestCase): @unittest.skipUnless( hasattr(GIMarshallingTests, "array_unichar_out"), "too old gi") def test_array_unichar_out(self): - if PY2: - result = [c.encode("utf-8") for c in list(CONSTANT_UCS4)] - else: - result = list(CONSTANT_UCS4) + result = list(CONSTANT_UCS4) assert GIMarshallingTests.array_unichar_out() == result @unittest.skip("broken") @@ -1627,10 +1580,7 @@ class TestGValue(unittest.TestCase): GLib.MAXINT + 1, GLib.MININT, GLib.MAXINT)): GIMarshallingTests.gvalue_flat_array([GLib.MAXINT + 1, "42", True]) - if PY2: - min_, max_ = GLib.MINLONG, GLib.MAXLONG - else: - min_, max_ = GLib.MININT, GLib.MAXINT + min_, max_ = GLib.MININT, GLib.MAXINT with pytest.raises( OverflowError, @@ -1651,7 +1601,7 @@ class TestGValue(unittest.TestCase): gc.collect() assert obj.__grefcount__ == grefcount - @unittest.skipIf(platform.python_implementation() == "PyPy" and PY3, "fixme") + @unittest.skipIf(platform.python_implementation() == "PyPy", "fixme") def test_gvalue_gobject_ref_counts(self): # Tests a GObject held by a GValue obj = GObject.Object() @@ -2908,10 +2858,7 @@ class TestMRO(unittest.TestCase): # style mixin. type('GIWithOldStyleMixin', (GIMarshallingTests.Object, Mixin), {}) - if PY2: - self.assertTrue(issubclass(warn[0].category, RuntimeWarning)) - else: - self.assertEqual(len(warn), 0) + self.assertEqual(len(warn), 0) class TestInterfaceClash(unittest.TestCase): diff --git a/tests/test_gio.py b/tests/test_gio.py index f3111ea3..3b812c44 100644 --- a/tests/test_gio.py +++ b/tests/test_gio.py @@ -1,8 +1,6 @@ # -*- Mode: Python; py-indent-offset: 4 -*- # vim: tabstop=4 shiftwidth=4 expandtab -from __future__ import absolute_import - import os import unittest import warnings diff --git a/tests/test_glib.py b/tests/test_glib.py index 70be98e6..0a5cb3d6 100644 --- a/tests/test_glib.py +++ b/tests/test_glib.py @@ -1,7 +1,4 @@ # -*- Mode: Python -*- -# encoding: UTF-8 - -from __future__ import absolute_import import os import sys @@ -13,7 +10,6 @@ import subprocess import pytest from gi.repository import GLib from gi import PyGIDeprecationWarning -from gi._compat import PY3 class TestGLib(unittest.TestCase): @@ -83,12 +79,8 @@ class TestGLib(unittest.TestCase): if isinstance(f, bytes): return f if os.name == "nt": - if PY3: - return f.encode("utf-8", "surrogatepass") - else: - return f.encode("utf-8") + return f.encode("utf-8", "surrogatepass") else: - assert PY3 return os.fsencode(f) # this is locale dependent, so we cannot completely verify the result diff --git a/tests/test_gobject.py b/tests/test_gobject.py index bba12cb7..bc70676b 100644 --- a/tests/test_gobject.py +++ b/tests/test_gobject.py @@ -1,7 +1,5 @@ # -*- Mode: Python -*- -from __future__ import absolute_import - import sys import gc import unittest diff --git a/tests/test_gtk_template.py b/tests/test_gtk_template.py index 3a1c1f02..d3388b37 100644 --- a/tests/test_gtk_template.py +++ b/tests/test_gtk_template.py @@ -1,7 +1,3 @@ -# coding: UTF-8 - -from __future__ import absolute_import - import tempfile import os import pytest diff --git a/tests/test_gtype.py b/tests/test_gtype.py index b9d3349d..1d24f9f4 100644 --- a/tests/test_gtype.py +++ b/tests/test_gtype.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import unittest from gi.repository import GObject diff --git a/tests/test_import_machinery.py b/tests/test_import_machinery.py index fc1ba7be..a8d50059 100644 --- a/tests/test_import_machinery.py +++ b/tests/test_import_machinery.py @@ -1,15 +1,12 @@ # -*- Mode: Python; py-indent-offset: 4 -*- # vim: tabstop=4 shiftwidth=4 expandtab -from __future__ import absolute_import - import sys import unittest import gi.overrides import gi.module import gi.importer -from gi._compat import PY2, PY3 from gi.repository import Regress @@ -122,10 +119,7 @@ class TestImporter(unittest.TestCase): exception_string = str(context.exception) self.assertTrue('InvalidGObjectRepositoryModuleName' in exception_string) - - # The message of the custom exception in gi/importer.py is eaten in Python <3.3 - if sys.version_info >= (3, 3): - self.assertTrue('introspection typelib' in exception_string) + self.assertTrue('introspection typelib' in exception_string) def test_require_version_warning(self): check = gi.importer._check_require_version @@ -146,13 +140,8 @@ class TestImporter(unittest.TestCase): with self.assertRaises(ValueError): gi.require_version('GLib', 2.0) - # Test that unicode strings work in python 2 - if PY2: - gi.require_version('GLib', u'2.0') - - if PY3: - with self.assertRaises(ValueError): - gi.require_version('GLib', b'2.0') + with self.assertRaises(ValueError): + gi.require_version('GLib', b'2.0') def test_require_versions(self): import gi diff --git a/tests/test_interface.py b/tests/test_interface.py index ca1e0f47..ba20cb41 100644 --- a/tests/test_interface.py +++ b/tests/test_interface.py @@ -1,7 +1,5 @@ # -*- Mode: Python -*- -from __future__ import absolute_import - import unittest from gi.repository import GObject diff --git a/tests/test_internal_api.py b/tests/test_internal_api.py index 1ed822c8..51360376 100644 --- a/tests/test_internal_api.py +++ b/tests/test_internal_api.py @@ -1,13 +1,9 @@ -# -*- coding: utf-8 -*- # -*- Mode: Python -*- -from __future__ import absolute_import - import unittest import pytest from gi.repository import GLib, GObject -from gi._compat import PY3 import testhelper @@ -103,13 +99,8 @@ def test_to_unichar_conv(): assert testhelper.test_to_unichar_conv(u"A") == 65 assert testhelper.test_to_unichar_conv(u"Ä") == 196 - if PY3: - with pytest.raises(TypeError): - assert testhelper.test_to_unichar_conv(b"\x65") - else: - assert testhelper.test_to_unichar_conv(b"\x65") == 0x65 - with pytest.raises(ValueError): - assert testhelper.test_to_unichar_conv(b"\xff") + with pytest.raises(TypeError): + assert testhelper.test_to_unichar_conv(b"\x65") with pytest.raises(TypeError): testhelper.test_to_unichar_conv(object()) diff --git a/tests/test_iochannel.py b/tests/test_iochannel.py index 56a0aea9..c4c6e3d5 100644 --- a/tests/test_iochannel.py +++ b/tests/test_iochannel.py @@ -1,7 +1,4 @@ # -*- Mode: Python -*- -# encoding: UTF-8 - -from __future__ import absolute_import import os import unittest diff --git a/tests/test_mainloop.py b/tests/test_mainloop.py index 40a8b97b..48399d15 100644 --- a/tests/test_mainloop.py +++ b/tests/test_mainloop.py @@ -1,7 +1,5 @@ # -*- Mode: Python -*- -from __future__ import absolute_import - import os import select import signal diff --git a/tests/test_object_marshaling.py b/tests/test_object_marshaling.py index 3d8ebb84..d52ff54f 100644 --- a/tests/test_object_marshaling.py +++ b/tests/test_object_marshaling.py @@ -1,8 +1,6 @@ # -*- Mode: Python; py-indent-offset: 4 -*- # vim: tabstop=4 shiftwidth=4 expandtab -from __future__ import absolute_import - import unittest import weakref import gc diff --git a/tests/test_option.py b/tests/test_option.py index 251eb3ad..1dc496a0 100644 --- a/tests/test_option.py +++ b/tests/test_option.py @@ -1,16 +1,7 @@ #!/usr/bin/env python -from __future__ import absolute_import - import unittest -# py3k has StringIO in a different module -try: - from StringIO import StringIO - StringIO # pyflakes -except ImportError: - from io import StringIO - from gi.repository import GLib from .helper import capture_exceptions diff --git a/tests/test_ossig.py b/tests/test_ossig.py index 9340c02b..2d03f65c 100644 --- a/tests/test_ossig.py +++ b/tests/test_ossig.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 Christoph Reiter # # This library is free software; you can redistribute it and/or diff --git a/tests/test_overrides_gdk.py b/tests/test_overrides_gdk.py index 0ea9187c..e809da07 100644 --- a/tests/test_overrides_gdk.py +++ b/tests/test_overrides_gdk.py @@ -1,8 +1,6 @@ # -*- Mode: Python; py-indent-offset: 4 -*- # vim: tabstop=4 shiftwidth=4 expandtab -from __future__ import absolute_import - import re import os import sys diff --git a/tests/test_overrides_gdkpixbuf.py b/tests/test_overrides_gdkpixbuf.py index 5b2d3707..4edd9bf8 100644 --- a/tests/test_overrides_gdkpixbuf.py +++ b/tests/test_overrides_gdkpixbuf.py @@ -15,8 +15,6 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 # USA -from __future__ import absolute_import - import pytest from gi import PyGIDeprecationWarning diff --git a/tests/test_overrides_gio.py b/tests/test_overrides_gio.py index 8612d51e..de0e2352 100644 --- a/tests/test_overrides_gio.py +++ b/tests/test_overrides_gio.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import random import platform import warnings @@ -8,7 +6,6 @@ import pytest from gi.repository import Gio, GObject from gi import PyGIWarning -from gi._compat import cmp class Item(GObject.Object): @@ -42,6 +39,7 @@ def test_list_store_sort(): assert list(args) == user_data assert isinstance(a, NamedItem) assert isinstance(b, NamedItem) + cmp = lambda a, b: (a > b) - (a < b) return cmp(a.props.name, b.props.name) store[:] = items @@ -61,6 +59,7 @@ def test_list_store_insert_sorted(): assert list(args) == user_data assert isinstance(a, NamedItem) assert isinstance(b, NamedItem) + cmp = lambda a, b: (a > b) - (a < b) return cmp(a.props.name, b.props.name) for item in items: diff --git a/tests/test_overrides_glib.py b/tests/test_overrides_glib.py index ac19ccd9..d8f1a6c0 100644 --- a/tests/test_overrides_glib.py +++ b/tests/test_overrides_glib.py @@ -1,8 +1,6 @@ # -*- Mode: Python; py-indent-offset: 4 -*- # vim: tabstop=4 shiftwidth=4 expandtab -from __future__ import absolute_import - import os import gc import unittest @@ -13,7 +11,6 @@ import pytest import gi from gi.repository import GLib -from gi._compat import long_, integer_types from .helper import capture_gi_deprecation_warnings @@ -183,7 +180,7 @@ class TestGVariant(unittest.TestCase): # nested tuples variant = GLib.Variant('((si)(ub))', (('hello', -1), (42, True))) self.assertEqual(variant.get_type_string(), '((si)(ub))') - self.assertEqual(variant.unpack(), (('hello', -1), (long_(42), True))) + self.assertEqual(variant.unpack(), (('hello', -1), (42, True))) def test_new_tuple_sink(self): # https://bugzilla.gnome.org/show_bug.cgi?id=735166 @@ -724,4 +721,4 @@ class TestConstants(unittest.TestCase): def test_basic_types_limits(self): self.assertTrue(isinstance(GLib.MINFLOAT, float)) - self.assertTrue(isinstance(GLib.MAXLONG, integer_types)) + self.assertTrue(isinstance(GLib.MAXLONG, int)) diff --git a/tests/test_overrides_gobject.py b/tests/test_overrides_gobject.py index 7f20e81a..dc265963 100644 --- a/tests/test_overrides_gobject.py +++ b/tests/test_overrides_gobject.py @@ -1,13 +1,8 @@ -# -*- coding: utf-8 -*- - -from __future__ import absolute_import - import pytest from gi import PyGIDeprecationWarning from gi.repository import GObject, GLib, GIMarshallingTests -from gi._compat import PY2 from .helper import ignore_gi_deprecation_warnings @@ -285,15 +280,8 @@ def test_value_string(): assert getter() is None - if PY2: + with pytest.raises(TypeError): setter(b"bar") - assert getter() == b"bar" - - setter(u"öäü") - assert getter().decode("utf-8") == u"öäü" - else: - with pytest.raises(TypeError): - setter(b"bar") setter(u"quux") assert getter() == u"quux" diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py index 4283d765..43537452 100644 --- a/tests/test_overrides_gtk.py +++ b/tests/test_overrides_gtk.py @@ -1,9 +1,6 @@ # -*- Mode: Python; py-indent-offset: 4 -*- -# coding: UTF-8 # vim: tabstop=4 shiftwidth=4 expandtab -from __future__ import absolute_import - import contextlib import unittest import sys @@ -17,7 +14,6 @@ from .helper import ignore_gi_deprecation_warnings, capture_glib_warnings import gi.overrides import gi.types -from gi._compat import cmp from gi.repository import GLib, GObject try: @@ -2358,6 +2354,7 @@ class TestTreeModel(unittest.TestCase): def sort_func(store, iter1, iter2, data): assert data is None + cmp = lambda a, b: (a > b) - (a < b) return cmp(store[iter1][0], store[iter2][0]) list_store.set_default_sort_func(sort_func) diff --git a/tests/test_overrides_pango.py b/tests/test_overrides_pango.py index a08880bd..2ec4cb12 100644 --- a/tests/test_overrides_pango.py +++ b/tests/test_overrides_pango.py @@ -1,8 +1,6 @@ # -*- Mode: Python; py-indent-offset: 4 -*- # vim: tabstop=4 shiftwidth=4 expandtab -from __future__ import absolute_import - import unittest try: diff --git a/tests/test_properties.py b/tests/test_properties.py index 35b03b71..ec5df0ca 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -1,7 +1,3 @@ -# coding=utf-8 - -from __future__ import absolute_import - import os import gc import sys @@ -31,7 +27,6 @@ from gi.repository import GIMarshallingTests from gi.repository import Regress from gi import _propertyhelper as propertyhelper -from gi._compat import long_, PY3, PY2 from .helper import capture_glib_warnings @@ -182,10 +177,7 @@ class TestPropertyObject(unittest.TestCase): def test_utf8_lone_surrogate(self): obj = PropertyObject() - if PY3: - with pytest.raises(TypeError): - obj.set_property('construct', '\ud83d') - else: + with pytest.raises(TypeError): obj.set_property('construct', '\ud83d') def test_int_to_str(self): @@ -207,12 +199,12 @@ class TestPropertyObject(unittest.TestCase): def test_uint64(self): obj = new(PropertyObject) self.assertEqual(obj.props.uint64, 0) - obj.props.uint64 = long_(1) - self.assertEqual(obj.props.uint64, long_(1)) obj.props.uint64 = 1 - self.assertEqual(obj.props.uint64, long_(1)) + self.assertEqual(obj.props.uint64, 1) + obj.props.uint64 = 1 + self.assertEqual(obj.props.uint64, 1) - self.assertRaises((TypeError, OverflowError), obj.set_property, "uint64", long_(-1)) + self.assertRaises((TypeError, OverflowError), obj.set_property, "uint64", -1) self.assertRaises((TypeError, OverflowError), obj.set_property, "uint64", -1) def test_uint64_default_value(self): @@ -220,7 +212,7 @@ class TestPropertyObject(unittest.TestCase): class TimeControl(GObject.GObject): __gproperties__ = { 'time': (TYPE_UINT64, 'Time', 'Time', - long_(0), (1 << 64) - 1, long_(0), + 0, (1 << 64) - 1, 0, ParamFlags.READABLE) } except OverflowError: @@ -512,9 +504,9 @@ class TestProperty(unittest.TestCase): def test_simple(self): class C(GObject.GObject): str = GObject.Property(type=str) - int = GObject.Property(type=int) float = GObject.Property(type=float) - long = GObject.Property(type=long_) + long = GObject.Property(type=int) + int = GObject.Property(type=int) self.assertTrue(hasattr(C.props, 'str')) self.assertTrue(hasattr(C.props, 'int')) @@ -534,9 +526,9 @@ class TestProperty(unittest.TestCase): o.float = 3.14 self.assertEqual(o.float, 3.14) - self.assertEqual(o.long, long_(0)) - o.long = long_(100) - self.assertEqual(o.long, long_(100)) + self.assertEqual(o.long, 0) + o.long = 100 + self.assertEqual(o.long, 100) def test_custom_getter(self): class C(GObject.GObject): @@ -871,8 +863,6 @@ class TestProperty(unittest.TestCase): def test_python_to_glib_type_mapping(self): tester = GObject.Property() self.assertEqual(tester._type_from_python(int), GObject.TYPE_INT) - if PY2: - self.assertEqual(tester._type_from_python(long_), GObject.TYPE_LONG) self.assertEqual(tester._type_from_python(bool), GObject.TYPE_BOOLEAN) self.assertEqual(tester._type_from_python(float), GObject.TYPE_DOUBLE) self.assertEqual(tester._type_from_python(str), GObject.TYPE_STRING) diff --git a/tests/test_pycapi.py b/tests/test_pycapi.py index 969b78e5..d049a8db 100644 --- a/tests/test_pycapi.py +++ b/tests/test_pycapi.py @@ -1,6 +1,3 @@ -from __future__ import absolute_import - -import sys import unittest import ctypes from ctypes import c_void_p, py_object, c_char_p @@ -23,16 +20,10 @@ def get_capi(): ] api_obj = gi._gobject._PyGObject_API - if sys.version_info[0] == 2: - func_type = ctypes.PYFUNCTYPE(c_void_p, py_object) - PyCObject_AsVoidPtr = func_type( - ('PyCObject_AsVoidPtr', ctypes.pythonapi)) - ptr = PyCObject_AsVoidPtr(api_obj) - else: - func_type = ctypes.PYFUNCTYPE(c_void_p, py_object, c_char_p) - PyCapsule_GetPointer = func_type( - ('PyCapsule_GetPointer', ctypes.pythonapi)) - ptr = PyCapsule_GetPointer(api_obj, b"gobject._PyGObject_API") + func_type = ctypes.PYFUNCTYPE(c_void_p, py_object, c_char_p) + PyCapsule_GetPointer = func_type( + ('PyCapsule_GetPointer', ctypes.pythonapi)) + ptr = PyCapsule_GetPointer(api_obj, b"gobject._PyGObject_API") ptr = ctypes.cast(ptr, ctypes.POINTER(CAPI)) return ptr.contents diff --git a/tests/test_pygtkcompat.py b/tests/test_pygtkcompat.py index 3e6a69ea..c01892a1 100644 --- a/tests/test_pygtkcompat.py +++ b/tests/test_pygtkcompat.py @@ -1,8 +1,6 @@ # -*- Mode: Python; py-indent-offset: 4 -*- # vim: tabstop=4 shiftwidth=4 expandtab -from __future__ import absolute_import - import unittest import base64 diff --git a/tests/test_repository.py b/tests/test_repository.py index 2da7f5a6..0aa29b63 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -20,13 +20,9 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 # USA -from __future__ import absolute_import import unittest -try: - from collections import abc -except ImportError: - import collections as abc +from collections import abc import gi._gi as GIRepository from gi.module import repository as repo diff --git a/tests/test_resulttuple.py b/tests/test_resulttuple.py index 45764952..00daa7b7 100644 --- a/tests/test_resulttuple.py +++ b/tests/test_resulttuple.py @@ -18,8 +18,6 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 # USA -from __future__ import absolute_import - import unittest import pickle diff --git a/tests/test_signal.py b/tests/test_signal.py index 68592c5d..e327d374 100644 --- a/tests/test_signal.py +++ b/tests/test_signal.py @@ -1,7 +1,5 @@ # -*- Mode: Python -*- -from __future__ import absolute_import - import gc import unittest import sys @@ -12,7 +10,6 @@ import time from gi.repository import GObject, GLib, Regress, Gio from gi import _signalhelper as signalhelper from gi.module import repository as repo -from gi._compat import PY3, long_ import testhelper from .helper import capture_glib_warnings, capture_gi_deprecation_warnings @@ -523,7 +520,7 @@ class CM(GObject.GObject): test2=(GObject.SignalFlags.RUN_LAST, None, (str,)), test3=(GObject.SignalFlags.RUN_LAST, int, (GObject.TYPE_DOUBLE,)), test4=(GObject.SignalFlags.RUN_FIRST, None, - (bool, long_, GObject.TYPE_FLOAT, GObject.TYPE_DOUBLE, int, + (bool, int, GObject.TYPE_FLOAT, GObject.TYPE_DOUBLE, int, GObject.TYPE_UINT, GObject.TYPE_ULONG)), test_float=(GObject.SignalFlags.RUN_LAST, GObject.TYPE_FLOAT, (GObject.TYPE_FLOAT,)), test_double=(GObject.SignalFlags.RUN_LAST, GObject.TYPE_DOUBLE, (GObject.TYPE_DOUBLE,)), @@ -555,7 +552,7 @@ class _TestCMarshaller: self.assertEqual(rv, 20) def test_test4(self): - self.obj.emit("test4", True, long_(10), 3.14, 1.78, 20, long_(30), long_(31)) + self.obj.emit("test4", True, 10, 3.14, 1.78, 20, 30, 31) def test_float(self): rv = self.obj.emit("test-float", 1.234) @@ -1015,28 +1012,16 @@ class TestInstallSignals(unittest.TestCase): self.assertTrue(hasattr(self.Sub2, 'do_sub2test')) -# For this test to work with both python2 and 3 we need to dynamically -# exec the given code due to the new syntax causing an error in python 2. -annotated_class_code = """ -class AnnotatedSignalClass(GObject.GObject): - @GObject.Signal - def sig1(self, a:int, b:float): - pass - - @GObject.Signal(flags=GObject.SignalFlags.RUN_LAST) - def sig2_with_return(self, a:int, b:float) -> str: - return "test" -""" - - -@unittest.skipUnless(PY3, 'Argument annotations require Python 3') class TestPython3Signals(unittest.TestCase): - AnnotatedClass = None - def setUp(self): - exec(annotated_class_code, globals(), globals()) - self.assertTrue('AnnotatedSignalClass' in globals()) - self.AnnotatedClass = globals()['AnnotatedSignalClass'] + class AnnotatedClass(GObject.GObject): + @GObject.Signal + def sig1(self, a: int, b: float): + pass + + @GObject.Signal(flags=GObject.SignalFlags.RUN_LAST) + def sig2_with_return(self, a: int, b: float) -> str: + return "test" def test_annotations(self): self.assertEqual(signalhelper.get_signal_annotations(self.AnnotatedClass.sig1.func), diff --git a/tests/test_source.py b/tests/test_source.py index 1a600fd7..9249892e 100644 --- a/tests/test_source.py +++ b/tests/test_source.py @@ -1,7 +1,5 @@ # -*- Mode: Python -*- -from __future__ import absolute_import - import sys import gc import unittest diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py index bd1056e0..274a501f 100644 --- a/tests/test_subprocess.py +++ b/tests/test_subprocess.py @@ -1,7 +1,5 @@ # -*- Mode: Python -*- -from __future__ import absolute_import - import sys import os import unittest diff --git a/tests/test_thread.py b/tests/test_thread.py index 45ebd0b5..334eff05 100644 --- a/tests/test_thread.py +++ b/tests/test_thread.py @@ -1,7 +1,5 @@ # -*- Mode: Python -*- -from __future__ import absolute_import - import unittest from gi.repository import GLib diff --git a/tests/test_typeclass.py b/tests/test_typeclass.py index b584fdd9..1f34a09d 100644 --- a/tests/test_typeclass.py +++ b/tests/test_typeclass.py @@ -20,8 +20,6 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 # USA -from __future__ import absolute_import - import unittest from gi.repository import GObject diff --git a/tests/test_unknown.py b/tests/test_unknown.py index 1ed1fb88..76fa185e 100644 --- a/tests/test_unknown.py +++ b/tests/test_unknown.py @@ -1,7 +1,5 @@ # -*- Mode: Python -*- -from __future__ import absolute_import - import unittest from gi.repository import GObject |