8000 Use numbers.Integral on python2 · nirum-lang/nirum-python@94bc1fd · GitHub
[go: up one dir, main page]

Skip to content

Commit 94bc1fd

Browse files
committed
Use numbers.Integral on python2
1 parent 0752cb9 commit 94bc1fd

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

nirum/deserialize.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import datetime
66
import decimal
77
import enum
8+
import numbers
89
import typing
910
import uuid
1011

@@ -26,7 +27,7 @@
2627
)
2728
_NIRUM_PRIMITIVE_TYPE = {
2829
float, decimal.Decimal, uuid.UUID, datetime.datetime,
29-
datetime.date, bool, int, text_type
30+
datetime.date, bool, int, text_type, numbers.Integral
3031
}
3132

3233

@@ -122,6 +123,8 @@ def deserialize_primitive(cls, data):
122123
raise ValueError("'{}' is not a date.".format(data))
123124
elif cls in {int, float, uuid.UUID, bool}:
124125
d = cls(data)
126+
elif cls is numbers.Integral:
127+
d = data
125128
elif cls is decimal.Decimal:
126129
try:
127130
d = cls(data)

tests/deserialize_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import datetime
22
import decimal
3+
import numbers
34
import uuid
45
import typing
56

67
from pytest import raises, mark
7-
from six import text_type
8+
from six import PY3, text_type
89

910
from nirum._compat import utc
1011
from nirum.serialize import serialize_record_type
@@ -121,7 +122,7 @@ def test_deserialize_multiple_boxed_type(fx_layered_boxed_types):
121122
@mark.parametrize(
122123
'data, t, expect',
123124
[
124-
(1, int, 1),
125+
(1, int if PY3 else numbers.Integral, 1),
125126
(1.1, float, 1.1),
126127
(u'hello', text_type, 'hello'),
127128
(True, bool, True),

0 commit comments

Comments
 (0)
0