[pypy-svn] r15025 - in pypy/dist/pypy/objspace/std: . test
arigo at codespeak.net
arigo at codespeak.net
Mon Jul 25 15:46:00 CEST 2005
Author: arigo
Date: Mon Jul 25 15:45:56 2005
New Revision: 15025
Modified:
pypy/dist/pypy/objspace/std/intobject.py
pypy/dist/pypy/objspace/std/longobject.py
pypy/dist/pypy/objspace/std/test/test_longobject.py
Log:
Removed the special case "-1" for hash(int).
Changed the interface of _FromDouble() to raise an interp-level OverflowError.
Modified: pypy/dist/pypy/objspace/std/intobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/intobject.py (original)
+++ pypy/dist/pypy/objspace/std/intobject.py Mon Jul 25 15:45:56 2005
@@ -99,31 +99,11 @@
j = w_int2.intval
return space.newbool( i >= j )
-STRICT_HASH = True # temporary, to be put elsewhere or removed
-
-def _hash_strict(space, w_int1):
- #/* XXX If this is changed, you also need to change the way
- # Python's long, float and complex types are hashed. */
- x = w_int1.intval
- if x == -1:
- x = -2
- return W_IntObject(space, x)
-
-def _hash_liberal(space, w_int1):
- # Armin: unlike CPython we have no need to special-case the value -1
- return w_int1
-
-# Chris: I'm not yet convinced that we want to make hash()
-# return different values that CPython does.
-# So for the moment, both versions are here,
-# and we might think of some config options
-# or decide to drop compatibility (using pypy-dev).
-
def hash__Int(space, w_int1):
- if STRICT_HASH:
- return _hash_strict(space, w_int1)
- else:
- return _hash_liberal(space, w_int1)
+ # unlike CPython, we don't special-case the value -1 in most of our
+ # hash functions, so there is not much sense special-casing it here either.
+ # Make sure this is consistent with the hash of floats and longs.
+ return int__Int(space, w_int1)
# coerce
def coerce__Int_Int(space, w_int1, w_int2):
Modified: pypy/dist/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/longobject.py (original)
+++ pypy/dist/pypy/objspace/std/longobject.py Mon Jul 25 15:45:56 2005
@@ -204,7 +204,11 @@
space.wrap("long int too large to convert to float"))
def long__Float(space, w_floatobj):
- return _FromDouble(space, w_floatobj.floatval)
+ try:
+ return _FromDouble(space, w_floatobj.floatval)
+ except OverflowError:
+ raise OperationError(space.w_OverflowError,
+ space.wrap("cannot convert float infinity to long"))
def int_w__Long(space, w_value):
try:
@@ -1303,8 +1307,7 @@
""" Create a new long int object from a C double """
neg = 0
if isinf(dval):
- raise OperationError(space.w_OverflowError,
- space.wrap("cannot convert float infinity to long"))
+ raise OverflowError
if dval < 0.0:
neg = 1
dval = -dval
@@ -1604,6 +1607,4 @@
x += v.digits[i]
i -= 1
x = intmask(x * sign)
- if x == -1:
- x = -2
return x
Modified: pypy/dist/pypy/objspace/std/test/test_longobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_longobject.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_longobject.py Mon Jul 25 15:45:56 2005
@@ -123,10 +123,7 @@
assert f1.longval() == long(x)
# check overflow
x = 12345.6789e10000000000000000000000000000
- try:
- lobj._FromDouble(self.space, x)
- except OperationError, e:
- assert e.w_type is self.space.w_OverflowError
+ assert raises(OverflowError, lobj._FromDouble, self.space, x)
# testing Karatsuba stuff
def test__v_iadd(self):
More information about the Pypy-commit
mailing list