summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2018-04-07 17:56:24 +0200
committerChristoph Reiter <reiter.christoph@gmail.com>2018-04-07 17:56:24 +0200
commit1f52c1ba5b48364c91d5eb99d1a5bb47b455b259 (patch)
tree2b8c1804c1f5263b824bea886867800a1eb735ea
parent83d792376fd2d1f4d8b251e104876c192758b3b2 (diff)
downloadpygobject-1f52c1ba5b48364c91d5eb99d1a5bb47b455b259.tar.gz
Move all py2/3 compat code into gi._compat
-rw-r--r--gi/__init__.py9
-rw-r--r--gi/_compat.py50
-rw-r--r--gi/_option.py19
-rw-r--r--gi/_propertyhelper.py16
-rw-r--r--gi/overrides/GObject.py4
-rw-r--r--gi/overrides/Gtk.py17
-rw-r--r--pygtkcompat/pygtkcompat.py25
-rw-r--r--tests/compathelper.py46
-rw-r--r--tests/conftest.py2
-rw-r--r--tests/helper.py3
-rw-r--r--tests/test_everything.py10
-rw-r--r--tests/test_gi.py6
-rw-r--r--tests/test_glib.py3
-rw-r--r--tests/test_import_machinery.py6
-rw-r--r--tests/test_overrides_glib.py6
-rw-r--r--tests/test_properties.py22
-rw-r--r--tests/test_signal.py9
17 files changed, 114 insertions, 139 deletions
diff --git a/gi/__init__.py b/gi/__init__.py
index 185c4d40..212136e5 100644
--- a/gi/__init__.py
+++ b/gi/__init__.py
@@ -44,6 +44,7 @@ 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
@@ -108,12 +109,8 @@ def require_version(namespace, version):
"""
repository = Repository.get_default()
- if sys.version_info[0] <= 2:
- if not isinstance(version, basestring):
- raise ValueError('Namespace version needs to be a string.')
- else:
- if not isinstance(version, str):
- raise ValueError('Namespace version needs to be a string.')
+ if not isinstance(version, string_types):
+ raise ValueError('Namespace version needs to be a string.')
if namespace in repository.get_loaded_namespaces():
loaded_version = repository.get_version(namespace)
diff --git a/gi/_compat.py b/gi/_compat.py
new file mode 100644
index 00000000..57a2b8ec
--- /dev/null
+++ b/gi/_compat.py
@@ -0,0 +1,50 @@
+# 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_ = long
+ integer_types = (int, long)
+ string_types = (basestring,)
+
+ exec("reload = reload")
+
+ 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,)
+
+ from importlib import reload
+ reload
+
+ def reraise(tp, value, tb):
+ raise tp(value).with_traceback(tb)
diff --git a/gi/_option.py b/gi/_option.py
index 45c74a3b..f1c8169c 100644
--- a/gi/_option.py
+++ b/gi/_option.py
@@ -32,13 +32,7 @@ import optparse
from optparse import OptParseError, OptionError, OptionValueError, \
BadOptionError, OptionConflictError
from .module import get_introspection_module
-
-if sys.version_info >= (3, 0):
- _basestring = str
- _bytes = lambda s: s.encode()
-else:
- _basestring = basestring
- _bytes = str
+from ._compat import string_types
from gi import _gi
from gi._error import GError
@@ -137,10 +131,13 @@ class Option(optparse.Option):
flags |= GLib.OptionFlags.FILENAME
for (long_name, short_name) in zip(self._long_opts, self._short_opts):
- yield (long_name[2:], _bytes(short_name[1]), flags, self.help, self.metavar)
+ short_bytes = short_name[1]
+ if not isinstance(short_bytes, bytes):
+ short_bytes = short_bytes.encode()
+ yield (long_name[2:], short_bytes, flags, self.help, self.metavar)
for long_name in self._long_opts[len(self._short_opts):]:
- yield (long_name[2:], _bytes('\0'), flags, self.help, self.metavar)
+ yield (long_name[2:], b'\0', flags, self.help, self.metavar)
class OptionGroup(optparse.OptionGroup):
@@ -233,7 +230,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, _basestring):
+ if isinstance(default, string_types):
opt_str = option.get_opt_string()
self.defaults[option.dest] = option.check_value(
opt_str, default)
@@ -313,7 +310,7 @@ class OptionParser(optparse.OptionParser):
return context
def add_option_group(self, *args, **kwargs):
- if isinstance(args[0], _basestring):
+ if isinstance(args[0], string_types):
optparse.OptionParser.add_option_group(self,
OptionGroup(self, *args, **kwargs))
return
diff --git a/gi/_propertyhelper.py b/gi/_propertyhelper.py
index 8690b8a0..a4b5e178 100644
--- a/gi/_propertyhelper.py
+++ b/gi/_propertyhelper.py
@@ -17,11 +17,10 @@
# 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
import traceback
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, \
@@ -39,13 +38,6 @@ G_MINLONG = _gi.G_MINLONG
G_MAXLONG = _gi.G_MAXLONG
G_MAXULONG = _gi.G_MAXULONG
-if sys.version_info >= (3, 0):
- _basestring = str
- _long = int
-else:
- _basestring = basestring
- _long = long
-
class Property(object):
"""Creates a new Property which when used in conjunction with
@@ -104,7 +96,7 @@ class Property(object):
"""
_type_from_pytype_lookup = {
# Put long_ first in case long_ and int are the same so int clobbers long_
- _long: TYPE_LONG,
+ long_: TYPE_LONG,
int: TYPE_INT,
bool: TYPE_BOOLEAN,
float: TYPE_DOUBLE,
@@ -162,11 +154,11 @@ class Property(object):
self.default = self._get_default(default)
self._check_default()
- if not isinstance(nick, _basestring):
+ if not isinstance(nick, string_types):
raise TypeError("nick must be a string")
self.nick = nick
- if not isinstance(blurb, _basestring):
+ if not isinstance(blurb, string_types):
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/overrides/GObject.py b/gi/overrides/GObject.py
index 0d5a70ef..3f0d6c66 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -21,7 +21,6 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
-import sys
import warnings
from collections import namedtuple
@@ -30,6 +29,7 @@ import gi.module
from gi.overrides import override, deprecated_attr
from gi.repository import GLib
from gi import PyGIDeprecationWarning
+from gi._compat import PY2
from gi import _propertyhelper as propertyhelper
from gi import _signalhelper as signalhelper
@@ -263,7 +263,7 @@ class Value(GObjectModule.Value):
elif gtype == TYPE_STRING:
if isinstance(py_value, str):
py_value = str(py_value)
- elif sys.version_info < (3, 0):
+ elif PY2:
if isinstance(py_value, unicode):
py_value = py_value.encode('UTF-8')
else:
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 40ccf090..0cdd648f 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -27,12 +27,9 @@ from gi.repository import GObject
from .._ossighelper import wakeup_on_signal, register_sigint_fallback
from ..overrides import override, strip_boolean_result, deprecated_init
from ..module import get_introspection_module
+from .._compat import string_types
from gi import PyGIDeprecationWarning
-if sys.version_info >= (3, 0):
- _basestring = str
-else:
- _basestring = basestring
Gtk = get_introspection_module('Gtk')
@@ -388,7 +385,7 @@ if Gtk._version in ("2.0", "3.0"):
class UIManager(Gtk.UIManager):
def add_ui_from_string(self, buffer):
- if not isinstance(buffer, _basestring):
+ if not isinstance(buffer, string_types):
raise TypeError('buffer must be a string')
length = len(buffer.encode('UTF-8'))
@@ -457,7 +454,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, _basestring):
+ if not isinstance(buffer, string_types):
raise TypeError('buffer must be a string')
length = len(buffer)
@@ -465,7 +462,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, _basestring):
+ if not isinstance(buffer, string_types):
raise TypeError('buffer must be a string')
length = len(buffer)
@@ -731,7 +728,7 @@ class TextBuffer(Gtk.TextBuffer):
Gtk.TextBuffer.set_text(self, text, length)
def insert(self, iter, text, length=-1):
- if not isinstance(text, _basestring):
+ if not isinstance(text, string_types):
raise TypeError('text must be a string, not %s' % type(text))
Gtk.TextBuffer.insert(self, iter, text, length)
@@ -760,7 +757,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, _basestring):
+ if not isinstance(text, string_types):
raise TypeError('text must be a string, not %s' % type(text))
Gtk.TextBuffer.insert_at_cursor(self, text, length)
@@ -1177,7 +1174,7 @@ class TreePath(Gtk.TreePath):
def __new__(cls, path=0):
if isinstance(path, int):
path = str(path)
- elif not isinstance(path, _basestring):
+ elif not isinstance(path, string_types):
path = ":".join(str(val) for val in path)
if len(path) == 0:
diff --git a/pygtkcompat/pygtkcompat.py b/pygtkcompat/pygtkcompat.py
index 299e0d18..85eb35b2 100644
--- a/pygtkcompat/pygtkcompat.py
+++ b/pygtkcompat/pygtkcompat.py
@@ -35,20 +35,9 @@ a well behaved PyGTK application mostly unmodified on top of PyGI.
import sys
import warnings
-try:
- # Python 3
- from collections import UserList
- UserList # pyflakes
- with warnings.catch_warnings():
- warnings.simplefilter('ignore')
- from imp import reload
-except ImportError:
- # Python 2 ships that in a different module
- from UserList import UserList
- UserList # pyflakes
-
import gi
from gi.repository import GObject
+from gi import _compat
_patches = []
@@ -160,8 +149,8 @@ def _disable_all():
sys.modules[name] = old_value
del _module_patches[:]
- reload(sys)
- if sys.version_info < (3, 0):
+ _compat.reload(sys)
+ if _compat.PY2:
sys.setdefaultencoding('ascii')
@@ -173,8 +162,8 @@ def enable_gtk(version='3.0'):
raise ValueError("version 4.0 not supported")
# set the default encoding like PyGTK
- reload(sys)
- if sys.version_info < (3, 0):
+ _compat.reload(sys)
+ if _compat.PY2:
sys.setdefaultencoding('utf-8')
# atk
@@ -460,11 +449,11 @@ def enable_gtk(version='3.0'):
orig_size_request = Gtk.Widget.size_request
def size_request(widget):
- class SizeRequest(UserList):
+ class SizeRequest(_compat.UserList):
def __init__(self, req):
self.height = req.height
self.width = req.width
- UserList.__init__(self, [self.width, self.height])
+ _compat.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)
diff --git a/tests/compathelper.py b/tests/compathelper.py
deleted file mode 100644
index 4ed38944..00000000
--- a/tests/compathelper.py
+++ /dev/null
@@ -1,46 +0,0 @@
-import sys
-
-PY2 = PY3 = False
-
-if sys.version_info >= (3, 0):
- '''
- for tests that need to test long values in python 2
-
- python 3 does not differentiate between long and int
- and does not supply a long keyword
-
- instead of testing longs by using values such as 10L
- test writters should do this:
-
- from compathelper import _long
- _long(10)
- '''
- _long = int
-
- '''
- for tests that need to test string values in python 2
-
- python 3 does differentiate between str and bytes
- and does not supply a basestring keyword
-
- any tests that use basestring should do this:
-
- from compathelper import _basestring
- isinstance(_basestring, "hello")
- '''
- _basestring = str
-
- from io import StringIO
- StringIO
- PY3 = True
-
- def reraise(tp, value, tb):
- raise tp(value).with_traceback(tb)
-else:
- _long = long
- _basestring = basestring
- from StringIO import StringIO
- StringIO
- PY2 = True
-
- exec("def reraise(tp, value, tb):\n raise tp, value, tb")
diff --git a/tests/conftest.py b/tests/conftest.py
index f69405d4..50b3f75f 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -4,7 +4,7 @@ import sys
import pytest
-from .compathelper import reraise
+from gi._compat import reraise
@pytest.hookimpl(hookwrapper=True)
diff --git a/tests/helper.py b/tests/helper.py
index 22d1b503..1485ec3d 100644
--- a/tests/helper.py
+++ b/tests/helper.py
@@ -11,8 +11,7 @@ from collections import namedtuple
import gi
from gi import PyGIDeprecationWarning
from gi.repository import GLib
-
-from .compathelper import StringIO
+from gi._compat import StringIO
ExceptionInfo = namedtuple("ExceptionInfo", ["type", "value", "traceback"])
diff --git a/tests/test_everything.py b/tests/test_everything.py
index eecd0e79..eab9b95d 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -16,6 +16,7 @@ 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
@@ -23,11 +24,10 @@ try:
except:
Gtk = None
-from .compathelper import PY3
from .helper import capture_exceptions
-if sys.version_info < (3, 0):
+if PY2:
UNICHAR = "\xe2\x99\xa5"
PY2_UNICODE_UNICHAR = unicode(UNICHAR, 'UTF-8')
else:
@@ -35,7 +35,7 @@ else:
const_str = b'const \xe2\x99\xa5 utf8'
-if sys.version_info >= (3, 0):
+if PY3:
const_str = const_str.decode('UTF-8')
noconst_str = 'non' + const_str
@@ -181,7 +181,7 @@ class TestEverything(unittest.TestCase):
def test_unichar(self):
self.assertEqual("c", Everything.test_unichar("c"))
- if sys.version_info < (3, 0):
+ if PY2:
self.assertEqual(UNICHAR, Everything.test_unichar(PY2_UNICODE_UNICHAR))
self.assertEqual(UNICHAR, Everything.test_unichar(UNICHAR))
self.assertRaises(TypeError, Everything.test_unichar, "")
@@ -403,7 +403,7 @@ class TestEverything(unittest.TestCase):
self.assertEqual(Everything.test_array_int_inout([]), [])
def test_array_gint8_in(self):
- if sys.version_info >= (3, 0):
+ if PY3:
self.assertEqual(Everything.test_array_gint8_in(b'\x01\x03\x05'), 9)
self.assertEqual(Everything.test_array_gint8_in([1, 3, 5, -50]), -41)
diff --git a/tests/test_gi.py b/tests/test_gi.py
index abc661e1..2a6466cf 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -22,9 +22,9 @@ 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 .compathelper import PY2, PY3
from .helper import capture_exceptions, capture_output
@@ -688,7 +688,7 @@ class TestUtf8(unittest.TestCase):
def test_utf8_none_in(self):
GIMarshallingTests.utf8_none_in(CONSTANT_UTF8)
- if sys.version_info < (3, 0):
+ if PY2:
GIMarshallingTests.utf8_none_in(CONSTANT_UTF8.decode("utf-8"))
self.assertRaises(TypeError, GIMarshallingTests.utf8_none_in, 42)
@@ -2891,7 +2891,7 @@ class TestMRO(unittest.TestCase):
# style mixin.
type('GIWithOldStyleMixin', (GIMarshallingTests.Object, Mixin), {})
- if sys.version_info < (3, 0):
+ if PY2:
self.assertTrue(issubclass(warn[0].category, RuntimeWarning))
else:
self.assertEqual(len(warn), 0)
diff --git a/tests/test_glib.py b/tests/test_glib.py
index 5b64466c..565a8722 100644
--- a/tests/test_glib.py
+++ b/tests/test_glib.py
@@ -13,8 +13,7 @@ import subprocess
import pytest
from gi.repository import GLib
from gi import PyGIDeprecationWarning
-
-from .compathelper import PY3
+from gi._compat import PY3
class TestGLib(unittest.TestCase):
diff --git a/tests/test_import_machinery.py b/tests/test_import_machinery.py
index 9fbdd6e4..1433e59d 100644
--- a/tests/test_import_machinery.py
+++ b/tests/test_import_machinery.py
@@ -9,6 +9,7 @@ import unittest
import gi.overrides
import gi.module
import gi.importer
+from gi._compat import PY2, PY3
from gi.repository import Regress
@@ -146,9 +147,10 @@ class TestImporter(unittest.TestCase):
gi.require_version('GLib', 2.0)
# Test that unicode strings work in python 2
- if sys.version_info[0] <= 2:
+ if PY2:
gi.require_version('GLib', unicode('2.0'))
- else:
+
+ if PY3:
with self.assertRaises(ValueError):
gi.require_version('GLib', b'2.0')
diff --git a/tests/test_overrides_glib.py b/tests/test_overrides_glib.py
index d0a2d64c..4fd8b1d6 100644
--- a/tests/test_overrides_glib.py
+++ b/tests/test_overrides_glib.py
@@ -8,7 +8,7 @@ import unittest
import gi
from gi.repository import GLib
-from .compathelper import _long
+from gi._compat import long_, integer_types
class TestGVariant(unittest.TestCase):
@@ -62,7 +62,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), (long_(42), True)))
def test_new_tuple_sink(self):
# https://bugzilla.gnome.org/show_bug.cgi?id=735166
@@ -586,4 +586,4 @@ class TestConstants(unittest.TestCase):
def test_basic_types_limits(self):
self.assertTrue(isinstance(GLib.MINFLOAT, float))
- self.assertTrue(isinstance(GLib.MAXLONG, (int, _long)))
+ self.assertTrue(isinstance(GLib.MAXLONG, integer_types))
diff --git a/tests/test_properties.py b/tests/test_properties.py
index 948013c3..4beace00 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -31,7 +31,7 @@ from gi.repository import GIMarshallingTests
from gi.repository import Regress
from gi import _propertyhelper as propertyhelper
-from .compathelper import _long, PY3
+from gi._compat import long_, PY3, PY2
from .helper import capture_glib_warnings, capture_output
@@ -207,12 +207,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 = 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, long_(1))
- self.assertRaises((TypeError, OverflowError), obj.set_property, "uint64", _long(-1))
+ self.assertRaises((TypeError, OverflowError), obj.set_property, "uint64", long_(-1))
self.assertRaises((TypeError, OverflowError), obj.set_property, "uint64", -1)
def test_uint64_default_value(self):
@@ -220,7 +220,7 @@ class TestPropertyObject(unittest.TestCase):
class TimeControl(GObject.GObject):
__gproperties__ = {
'time': (TYPE_UINT64, 'Time', 'Time',
- _long(0), (1 << 64) - 1, _long(0),
+ long_(0), (1 << 64) - 1, long_(0),
ParamFlags.READABLE)
}
except OverflowError:
@@ -514,7 +514,7 @@ class TestProperty(unittest.TestCase):
str = GObject.Property(type=str)
int = GObject.Property(type=int)
float = GObject.Property(type=float)
- long = GObject.Property(type=_long)
+ long = GObject.Property(type=long_)
self.assertTrue(hasattr(C.props, 'str'))
self.assertTrue(hasattr(C.props, 'int'))
@@ -534,9 +534,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, long_(0))
+ o.long = long_(100)
+ self.assertEqual(o.long, long_(100))
def test_custom_getter(self):
class C(GObject.GObject):
@@ -874,7 +874,7 @@ 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 sys.version_info < (3, 0):
+ 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)
diff --git a/tests/test_signal.py b/tests/test_signal.py
index 00ccf2d2..8fcc191c 100644
--- a/tests/test_signal.py
+++ b/tests/test_signal.py
@@ -12,9 +12,9 @@ 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_
from . import testhelper
-from .compathelper import _long
from .helper import capture_glib_warnings, capture_gi_deprecation_warnings
@@ -523,7 +523,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, long_, 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 +555,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, long_(10), 3.14, 1.78, 20, long_(30), long_(31))
def test_float(self):
rv = self.obj.emit("test-float", 1.234)
@@ -1005,8 +1005,7 @@ class AnnotatedSignalClass(GObject.GObject):
"""
-@unittest.skipUnless(sys.version_info >= (3, 0),
- 'Argument annotations require Python 3')
+@unittest.skipUnless(PY3, 'Argument annotations require Python 3')
class TestPython3Signals(unittest.TestCase):
AnnotatedClass = None