Author: Matt Bogosian <[email protected]>
Branch: posita/2193-datetime-timedelta-integrals
Changeset: r80864:7c2b59d96efe
Date: 2015-11-23 10:09 -0800
http://bitbucket.org/pypy/pypy/changeset/7c2b59d96efe/
Log: Fix #2193. `isinstance(..., int)` => `isinstance(...,
numbers.Integral)` to allow for alternate `int`-like implementations
(e.g., `future.types.newint`).
diff --git a/lib_pypy/datetime.py b/lib_pypy/datetime.py
--- a/lib_pypy/datetime.py
+++ b/lib_pypy/datetime.py
@@ -17,6 +17,7 @@
"""
from __future__ import division
+import numbers as _numbers
import time as _time
import math as _math
import struct as _struct
@@ -278,7 +279,7 @@
except AttributeError:
pass
else:
- if isinstance(value, (int, long)):
+ if isinstance(value, _numbers.Integral):
return value
raise TypeError('__int__ method should return an integer')
raise TypeError('an integer is required')
@@ -468,7 +469,7 @@
d = days
assert isinstance(daysecondsfrac, float)
assert abs(daysecondsfrac) <= 1.0
- assert isinstance(d, (int, long))
+ assert isinstance(d, _numbers.Integral)
assert abs(s) <= 24 * 3600
# days isn't referenced again before redefinition
@@ -484,11 +485,11 @@
assert isinstance(secondsfrac, float)
assert abs(secondsfrac) <= 2.0
- assert isinstance(seconds, (int, long))
+ assert isinstance(seconds, _numbers.Integral)
days, seconds = divmod(seconds, 24*3600)
d += days
s += int(seconds) # can't overflow
- assert isinstance(s, int)
+ assert isinstance(s, _numbers.Integral)
assert abs(s) <= 2 * 24 * 3600
# seconds isn't referenced again before redefinition
@@ -510,8 +511,8 @@
d += days
s += int(seconds)
microseconds = _round(microseconds + usdouble)
- assert isinstance(s, int)
- assert isinstance(microseconds, int)
+ assert isinstance(s, _numbers.Integral)
+ assert isinstance(microseconds, _numbers.Integral)
assert abs(s) <= 3 * 24 * 3600
assert abs(microseconds) < 3.1e6
@@ -521,9 +522,9 @@
days, s = divmod(s, 24*3600)
d += days
- assert isinstance(d, (int, long))
- assert isinstance(s, int) and 0 <= s < 24*3600
- assert isinstance(us, int) and 0 <= us < 1000000
+ assert isinstance(d, _numbers.Integral)
+ assert isinstance(s, _numbers.Integral) and 0 <= s < 24*3600
+ assert isinstance(us, _numbers.Integral) and 0 <= us < 1000000
if abs(d) > 999999999:
raise OverflowError("timedelta # of days is too large: %d" % d)
@@ -623,7 +624,7 @@
return self
def __mul__(self, other):
- if isinstance(other, (int, long)):
+ if isinstance(other, _numbers.Integral):
# for CPython compatibility, we cannot use
# our __class__ here, but need a real timedelta
return timedelta(self._days * other,
@@ -638,7 +639,7 @@
self._microseconds)
def __div__(self, other):
- if not isinstance(other, (int, long)):
+ if not isinstance(other, _numbers.Integral):
return NotImplemented
usec = self._to_microseconds()
return timedelta(0, 0, usec // other)
@@ -1510,7 +1511,7 @@
converter = _time.localtime if tz is None else _time.gmtime
- if isinstance(timestamp, int):
+ if isinstance(timestamp, _numbers.Integral):
us = 0
else:
t_full = timestamp
@@ -1535,7 +1536,7 @@
@classmethod
def utcfromtimestamp(cls, t):
"Construct a UTC datetime from a POSIX timestamp (like time.time())."
- if isinstance(t, int):
+ if isinstance(t, _numbers.Integral):
us = 0
else:
t_full = t
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit