From 0c059b85b1d4a495043a126938d53536fd0a8b6a Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Thu, 29 Oct 2015 22:18:27 +0100 Subject: [PATCH] compat: Replace (int, long) with compat.integer_types --- mopidy/compat.py | 2 ++ mopidy/internal/validation.py | 2 +- mopidy/models/fields.py | 3 ++- tests/__init__.py | 2 +- tests/core/test_history.py | 3 ++- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mopidy/compat.py b/mopidy/compat.py index 2293f677..5df43e74 100644 --- a/mopidy/compat.py +++ b/mopidy/compat.py @@ -29,6 +29,7 @@ if PY2: urllib = fake_python3_urllib_module() + integer_types = (int, long) string_types = basestring text_type = unicode @@ -43,6 +44,7 @@ else: import _thread as thread # noqa import urllib # noqa + integer_types = (int,) string_types = (str,) text_type = str diff --git a/mopidy/internal/validation.py b/mopidy/internal/validation.py index 166983c9..5e15d83b 100644 --- a/mopidy/internal/validation.py +++ b/mopidy/internal/validation.py @@ -56,7 +56,7 @@ def check_instances(arg, cls, msg='Expected a list of {name}, not {arg!r}'): def check_integer(arg, min=None, max=None): - if not isinstance(arg, (int, long)): + if not isinstance(arg, compat.integer_types): raise exceptions.ValidationError('Expected an integer, not %r' % arg) elif min is not None and arg < min: raise exceptions.ValidationError( diff --git a/mopidy/models/fields.py b/mopidy/models/fields.py index 2cc6e512..91cd2cad 100644 --- a/mopidy/models/fields.py +++ b/mopidy/models/fields.py @@ -121,7 +121,8 @@ class Integer(Field): def __init__(self, default=None, min=None, max=None): self._min = min self._max = max - super(Integer, self).__init__(type=(int, long), default=default) + super(Integer, self).__init__( + type=compat.integer_types, default=default) def validate(self, value): value = super(Integer, self).validate(value) diff --git a/tests/__init__.py b/tests/__init__.py index 5e18c9dd..99806e97 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -32,6 +32,6 @@ class IsA(object): return str(self.klass) -any_int = IsA((int, long)) +any_int = IsA(compat.integer_types) any_str = IsA(compat.string_types) any_unicode = IsA(compat.text_type) diff --git a/tests/core/test_history.py b/tests/core/test_history.py index 068518b6..7f034cad 100644 --- a/tests/core/test_history.py +++ b/tests/core/test_history.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals import unittest +from mopidy import compat from mopidy.core import HistoryController from mopidy.models import Artist, Track @@ -40,7 +41,7 @@ class PlaybackHistoryTest(unittest.TestCase): result = self.history.get_history() (timestamp, ref) = result[0] - self.assertIsInstance(timestamp, (int, long)) + self.assertIsInstance(timestamp, compat.integer_types) self.assertEqual(track.uri, ref.uri) self.assertIn(track.name, ref.name) for artist in track.artists: