Author: Brian Kearns <[email protected]>
Branch:
Changeset: r80873:89a6ae0a9ec2
Date: 2015-11-23 16:29 -0500
http://bitbucket.org/pypy/pypy/changeset/89a6ae0a9ec2/
Log: try to correct more differences in datetime
diff --git a/lib_pypy/datetime.py b/lib_pypy/datetime.py
--- a/lib_pypy/datetime.py
+++ b/lib_pypy/datetime.py
@@ -272,15 +272,17 @@
def _check_int_field(value):
if isinstance(value, int):
- return value
+ return int(value)
if not isinstance(value, float):
try:
value = value.__int__()
except AttributeError:
pass
else:
- if isinstance(value, _numbers.Integral):
- return value
+ if isinstance(value, int):
+ return int(value)
+ elif isinstance(value, long):
+ return int(long(value))
raise TypeError('__int__ method should return an integer')
raise TypeError('an integer is required')
raise TypeError('integer argument expected, got float')
@@ -624,7 +626,7 @@
return self
def __mul__(self, other):
- if isinstance(other, _numbers.Integral):
+ if isinstance(other, (int, long)):
# for CPython compatibility, we cannot use
# our __class__ here, but need a real timedelta
return timedelta(self._days * other,
@@ -639,7 +641,7 @@
self._microseconds)
def __div__(self, other):
- if not isinstance(other, _numbers.Integral):
+ if not isinstance(other, (int, long)):
return NotImplemented
usec = self._to_microseconds()
return timedelta(0, 0, usec // other)
diff --git a/pypy/module/test_lib_pypy/test_datetime.py
b/pypy/module/test_lib_pypy/test_datetime.py
--- a/pypy/module/test_lib_pypy/test_datetime.py
+++ b/pypy/module/test_lib_pypy/test_datetime.py
@@ -170,14 +170,23 @@
self.value = value
def __int__(self):
return self.value
+ class SubInt(int): pass
+ class SubLong(long): pass
+ dt10 = datetime.datetime(10, 10, 10, 10, 10, 10, 10)
for xx in [10L,
decimal.Decimal(10),
decimal.Decimal('10.9'),
Number(10),
- Number(10L)]:
- assert datetime.datetime(10, 10, 10, 10, 10, 10, 10) == \
- datetime.datetime(xx, xx, xx, xx, xx, xx, xx)
+ Number(10L),
+ SubInt(10),
+ SubLong(10),
+ Number(SubInt(10)),
+ Number(SubLong(10))]:
+ dtxx = datetime.datetime(xx, xx, xx, xx, xx, xx, xx)
+ assert dt10 == dtxx
+ assert type(dtxx.month) is int
+ assert type(dtxx.second) is int
with py.test.raises(TypeError) as e:
datetime.datetime(10, 10, '10')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit