[pypy-commit] pypy faster-rstruct: hg merge default
antocuni
noreply at buildbot.pypy.org
Tue Nov 24 12:59:37 EST 2015
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: faster-rstruct
Changeset: r80903:56589ed1776a
Date: 2015-11-24 18:57 +0100
http://bitbucket.org/pypy/pypy/changeset/56589ed1776a/
Log: hg merge default
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
@@ -271,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, (int, long)):
- 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')
@@ -468,7 +471,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 +487,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 +513,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 +524,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)
@@ -1510,7 +1513,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 +1538,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
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -15,4 +15,10 @@
Fix the cpyext tests on OSX by linking with -flat_namespace
.. branch: anntype
+
Refactor and improve exception analysis in the annotator.
+
+.. branch: posita/2193-datetime-timedelta-integrals
+
+Fix issue #2193. ``isinstance(..., int)`` => ``isinstance(..., numbers.Integral)``
+to allow for alternate ``int``-like implementations (e.g., ``future.types.newint``)
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')
@@ -242,6 +251,64 @@
naive == aware
assert str(e.value) == "can't compare offset-naive and offset-aware times"
+ def test_future_types_newint(self):
+ try:
+ from future.types.newint import newint
+ except ImportError:
+ py.test.skip('requires future')
+
+ dt_from_ints = datetime.datetime(2015, 12, 31, 12, 34, 56)
+ dt_from_newints = datetime.datetime(newint(2015), newint(12), newint(31), newint(12), newint(34), newint(56))
+ dt_from_mixed = datetime.datetime(2015, newint(12), 31, newint(12), 34, newint(56))
+ assert dt_from_ints == dt_from_newints
+ assert dt_from_newints == dt_from_mixed
+ assert dt_from_mixed == dt_from_ints
+
+ d_from_int = datetime.date.fromtimestamp(1431216000)
+ d_from_newint = datetime.date.fromtimestamp(newint(1431216000))
+ assert d_from_int == d_from_newint
+
+ dt_from_int = datetime.datetime.fromtimestamp(1431216000)
+ dt_from_newint = datetime.datetime.fromtimestamp(newint(1431216000))
+ assert dt_from_int == dt_from_newint
+
+ dtu_from_int = datetime.datetime.utcfromtimestamp(1431216000)
+ dtu_from_newint = datetime.datetime.utcfromtimestamp(newint(1431216000))
+ assert dtu_from_int == dtu_from_newint
+
+ td_from_int = datetime.timedelta(16565)
+ tds_from_int = datetime.timedelta(seconds=1431216000)
+ td_from_newint = datetime.timedelta(newint(16565))
+ tds_from_newint = datetime.timedelta(seconds=newint(1431216000))
+ assert td_from_int == tds_from_int
+ assert td_from_int == td_from_newint
+ assert td_from_int == tds_from_newint
+ assert tds_from_int == td_from_newint
+ assert tds_from_int == tds_from_newint
+ assert td_from_newint == tds_from_newint
+
+ td_mul_int_int = td_from_int * 2
+ td_mul_int_newint = td_from_int * newint(2)
+ td_mul_newint_int = td_from_newint * 2
+ td_mul_newint_newint = td_from_newint * newint(2)
+ assert td_mul_int_int == td_mul_int_newint
+ assert td_mul_int_int == td_mul_newint_int
+ assert td_mul_int_int == td_mul_newint_newint
+ assert td_mul_int_newint == td_mul_newint_int
+ assert td_mul_int_newint == td_mul_newint_newint
+ assert td_mul_newint_int == td_mul_newint_newint
+
+ td_div_int_int = td_from_int / 3600
+ td_div_int_newint = td_from_int / newint(3600)
+ td_div_newint_int = td_from_newint / 3600
+ td_div_newint_newint = td_from_newint / newint(3600)
+ assert td_div_int_int == td_div_int_newint
+ assert td_div_int_int == td_div_newint_int
+ assert td_div_int_int == td_div_newint_newint
+ assert td_div_int_newint == td_div_newint_int
+ assert td_div_int_newint == td_div_newint_newint
+ assert td_div_newint_int == td_div_newint_newint
+
class TestDatetimeHost(BaseTestDatetime):
def setup_class(cls):
diff --git a/rpython/jit/metainterp/optimizeopt/unroll.py b/rpython/jit/metainterp/optimizeopt/unroll.py
--- a/rpython/jit/metainterp/optimizeopt/unroll.py
+++ b/rpython/jit/metainterp/optimizeopt/unroll.py
@@ -314,9 +314,16 @@
args, virtuals = target_virtual_state.make_inputargs_and_virtuals(
args, self.optimizer)
short_preamble = target_token.short_preamble
- extra = self.inline_short_preamble(args + virtuals, args,
- short_preamble, self.optimizer.patchguardop,
- target_token, label_op)
+ try:
+ extra = self.inline_short_preamble(args + virtuals, args,
+ short_preamble, self.optimizer.patchguardop,
+ target_token, label_op)
+ except KeyError:
+ # SHOULD NOT OCCUR BUT DOES: WHY?? issue #2185
+ self.optimizer.metainterp_sd.logger_ops.log_short_preamble([],
+ short_preamble, {})
+ raise
+
self.send_extra_operation(jump_op.copy_and_change(rop.JUMP,
args=args + extra,
descr=target_token))
More information about the pypy-commit
mailing list