Skip to content

Commit 484e352

Browse files
committed
Silence 3.8 warnings about implicit __int__ conversion
1 parent 4de72c5 commit 484e352

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

codecs/int.pyx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ cdef int2_encode(CodecContext settings, WriteBuffer buf, obj):
2323
cdef long val
2424

2525
try:
26+
if type(obj) is not int and hasattr(type(obj), '__int__'):
27+
# Silence a Python warning about implicit __int__
28+
# conversion.
29+
obj = int(obj)
2630
val = cpython.PyLong_AsLong(obj)
2731
except OverflowError:
2832
overflow = 1
@@ -43,6 +47,10 @@ cdef int4_encode(CodecContext settings, WriteBuffer buf, obj):
4347
cdef long val = 0
4448

4549
try:
50+
if type(obj) is not int and hasattr(type(obj), '__int__'):
51+
# Silence a Python warning about implicit __int__
52+
# conversion.
53+
obj = int(obj)
4654
val = cpython.PyLong_AsLong(obj)
4755
except OverflowError:
4856
overflow = 1
@@ -64,6 +72,10 @@ cdef uint4_encode(CodecContext settings, WriteBuffer buf, obj):
6472
cdef unsigned long val = 0
6573

6674
try:
75+
if type(obj) is not int and hasattr(type(obj), '__int__'):
76+
# Silence a Python warning about implicit __int__
77+
# conversion.
78+
obj = int(obj)
6779
val = cpython.PyLong_AsUnsignedLong(obj)
6880
except OverflowError:
6981
overflow = 1
@@ -86,6 +98,10 @@ cdef int8_encode(CodecContext settings, WriteBuffer buf, obj):
8698
cdef long long val
8799

88100
try:
101+
if type(obj) is not int and hasattr(type(obj), '__int__'):
102+
# Silence a Python warning about implicit __int__
103+
# conversion.
104+
obj = int(obj)
89105
val = cpython.PyLong_AsLongLong(obj)
90106
except OverflowError:
91107
overflow = 1

0 commit comments

Comments
 (0)