Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r51325:f4af6649c12f
Date: 2011-12-27 17:22 +0100
http://bitbucket.org/pypy/pypy/changeset/f4af6649c12f/
Log: Break everything and unify int and long!
diff --git a/pypy/interpreter/astcompiler/astbuilder.py
b/pypy/interpreter/astcompiler/astbuilder.py
--- a/pypy/interpreter/astcompiler/astbuilder.py
+++ b/pypy/interpreter/astcompiler/astbuilder.py
@@ -1047,10 +1047,7 @@
w_num_str = self.space.wrap(raw)
w_index = None
w_base = self.space.wrap(base)
- if raw[-1] in "lL":
- tp = self.space.w_long
- return self.space.call_function(tp, w_num_str, w_base)
- elif raw[-1] in "jJ":
+ if raw[-1] in "jJ":
tp = self.space.w_complex
return self.space.call_function(tp, w_num_str)
try:
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1409,8 +1409,7 @@
# not os.close(). It's likely designed for 'select'. It's irregular
# in the sense that it expects either a real int/long or an object
# with a fileno(), but not an object with an __int__().
- if (not self.isinstance_w(w_fd, self.w_int) and
- not self.isinstance_w(w_fd, self.w_long)):
+ if not self.isinstance_w(w_fd, self.w_int):
try:
w_fileno = self.getattr(w_fd, self.wrap("fileno"))
except OperationError, e:
@@ -1519,7 +1518,6 @@
('int', 'int', 1, ['__int__']),
('index', 'index', 1, ['__index__']),
('float', 'float', 1, ['__float__']),
- ('long', 'long', 1, ['__long__']),
('inplace_add', '+=', 2, ['__iadd__']),
('inplace_sub', '-=', 2, ['__isub__']),
('inplace_mul', '*=', 2, ['__imul__']),
diff --git a/pypy/module/_io/interp_io.py b/pypy/module/_io/interp_io.py
--- a/pypy/module/_io/interp_io.py
+++ b/pypy/module/_io/interp_io.py
@@ -41,8 +41,7 @@
if not (space.isinstance_w(w_file, space.w_unicode) or
space.isinstance_w(w_file, space.w_str) or
- space.isinstance_w(w_file, space.w_int) or
- space.isinstance_w(w_file, space.w_long)):
+ space.isinstance_w(w_file, space.w_int)):
raise operationerrfmt(space.w_TypeError,
"invalid file: %s", space.str_w(space.repr(w_file))
)
diff --git a/pypy/module/_random/interp_random.py
b/pypy/module/_random/interp_random.py
--- a/pypy/module/_random/interp_random.py
+++ b/pypy/module/_random/interp_random.py
@@ -28,8 +28,6 @@
else:
if space.is_true(space.isinstance(w_n, space.w_int)):
w_n = space.abs(w_n)
- elif space.is_true(space.isinstance(w_n, space.w_long)):
- w_n = space.abs(w_n)
else:
# XXX not perfectly like CPython
w_n = space.abs(space.hash(w_n))
@@ -76,11 +74,13 @@
self._rnd.index = space.int_w(w_item)
def jumpahead(self, space, w_n):
- if space.is_true(space.isinstance(w_n, space.w_long)):
+ try:
+ n = space.int_w(w_n)
+ except OperationError, e:
+ if not e.match(space, space.w_TypeError):
+ raise
num = space.bigint_w(w_n)
n = intmask(num.uintmask())
- else:
- n = space.int_w(w_n)
self._rnd.jumpahead(n)
assert rbigint.SHIFT <= 32
diff --git a/pypy/module/_winreg/interp_winreg.py
b/pypy/module/_winreg/interp_winreg.py
--- a/pypy/module/_winreg/interp_winreg.py
+++ b/pypy/module/_winreg/interp_winreg.py
@@ -109,9 +109,14 @@
elif isinstance(w_hkey, W_HKEY):
return w_hkey.hkey
elif space.is_true(space.isinstance(w_hkey, space.w_int)):
- return rffi.cast(rwinreg.HKEY, space.int_w(w_hkey))
- elif space.is_true(space.isinstance(w_hkey, space.w_long)):
- return rffi.cast(rwinreg.HKEY, space.uint_w(w_hkey))
+ try:
+ value = space.int_w(w_hkey)
+ except OperationError, e:
+ if not e.match(space, space.w_TypeError):
+ raise
+ return rffi.cast(rwinreg.HKEY, space.uint_w(w_hkey))
+ else:
+ return rffi.cast(rwinreg.HKEY, space.int_w(w_hkey))
else:
errstring = space.wrap("The object is not a PyHKEY object")
raise OperationError(space.w_TypeError, errstring)
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -377,10 +377,9 @@
"Dict": "space.w_dict",
"Tuple": "space.w_tuple",
"List": "space.w_list",
- "Int": "space.w_int",
"Bool": "space.w_bool",
"Float": "space.w_float",
- "Long": "space.w_long",
+ "Long": "space.w_int",
"Complex": "space.w_complex",
"BaseObject": "space.w_object",
'None': 'space.type(space.w_None)',
diff --git a/pypy/module/cpyext/longobject.py b/pypy/module/cpyext/longobject.py
--- a/pypy/module/cpyext/longobject.py
+++ b/pypy/module/cpyext/longobject.py
@@ -126,7 +126,7 @@
@cpython_api([lltype.Float], PyObject)
def PyLong_FromDouble(space, val):
"""Return a new PyLongObject object from v, or NULL on failure."""
- return space.long(space.wrap(val))
+ return space.int(space.wrap(val))
@cpython_api([PyObject], lltype.Float, error=-1.0)
def PyLong_AsDouble(space, w_long):
@@ -151,7 +151,7 @@
w_base = space.wrap(rffi.cast(lltype.Signed, base))
if pend:
pend[0] = rffi.ptradd(str, len(s))
- return space.call_function(space.w_long, w_str, w_base)
+ return space.call_function(space.w_int, w_str, w_base)
@cpython_api([rffi.VOIDP], PyObject)
def PyLong_FromVoidPtr(space, p):
diff --git a/pypy/module/cpyext/number.py b/pypy/module/cpyext/number.py
--- a/pypy/module/cpyext/number.py
+++ b/pypy/module/cpyext/number.py
@@ -47,7 +47,7 @@
def PyNumber_Long(space, w_obj):
"""Returns the o converted to a long integer object on success, or NULL on
failure. This is the equivalent of the Python expression long(o)."""
- return space.long(w_obj)
+ return space.int(w_obj)
@cpython_api([PyObject], PyObject)
def PyNumber_Index(space, w_obj):
diff --git a/pypy/module/math/interp_math.py b/pypy/module/math/interp_math.py
--- a/pypy/module/math/interp_math.py
+++ b/pypy/module/math/interp_math.py
@@ -101,8 +101,7 @@
"""ldexp(x, i) -> x * (2**i)
"""
x = _get_double(space, w_x)
- if (space.isinstance_w(w_i, space.w_int) or
- space.isinstance_w(w_i, space.w_long)):
+ if space.isinstance_w(w_i, space.w_int):
try:
exp = space.int_w(w_i)
except OperationError, e:
@@ -189,7 +188,7 @@
def _log_any(space, w_x, base):
# base is supposed to be positive or 0.0, which means we use e
try:
- if space.is_true(space.isinstance(w_x, space.w_long)):
+ if space.is_true(space.isinstance(w_x, space.w_int)):
# special case to support log(extremely-large-long)
num = space.bigint_w(w_x)
result = num.log(base)
diff --git a/pypy/module/micronumpy/interp_dtype.py
b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -187,7 +187,7 @@
name="int64",
char="q",
w_box_type = space.gettypefor(interp_boxes.W_Int64Box),
- alternate_constructors=[space.w_long],
+ alternate_constructors=[space.w_int],
)
self.w_uint64dtype = W_Dtype(
types.UInt64(),
@@ -228,4 +228,4 @@
)
def get_dtype_cache(space):
- return space.fromcache(DtypeCache)
\ No newline at end of file
+ return space.fromcache(DtypeCache)
diff --git a/pypy/module/micronumpy/interp_ufuncs.py
b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -270,11 +270,6 @@
return current_guess
elif space.isinstance_w(w_obj, space.w_int):
if (current_guess is None or current_guess is bool_dtype or
- current_guess is long_dtype):
- return long_dtype
- return current_guess
- elif space.isinstance_w(w_obj, space.w_long):
- if (current_guess is None or current_guess is bool_dtype or
current_guess is long_dtype or current_guess is int64_dtype):
return int64_dtype
return current_guess
diff --git a/pypy/module/operator/interp_operator.py
b/pypy/module/operator/interp_operator.py
--- a/pypy/module/operator/interp_operator.py
+++ b/pypy/module/operator/interp_operator.py
@@ -226,8 +226,7 @@
raise OperationError(space.w_TypeError,
space.wrap("non-sequence object can't be repeated"))
- if not (space.is_true(space.isinstance(w_obj2, space.w_int)) or \
- space.is_true(space.isinstance(w_obj2, space.w_long))):
+ if not space.is_true(space.isinstance(w_obj2, space.w_int)):
# second arg has to be int/long
raise OperationError(space.w_TypeError,
space.wrap('an integer is required'))
diff --git a/pypy/module/struct/formatiterator.py
b/pypy/module/struct/formatiterator.py
--- a/pypy/module/struct/formatiterator.py
+++ b/pypy/module/struct/formatiterator.py
@@ -64,8 +64,7 @@
def _accept_integral(self, meth):
space = self.space
w_obj = self.accept_obj_arg()
- if (space.isinstance_w(w_obj, space.w_int) or
- space.isinstance_w(w_obj, space.w_long)):
+ if space.isinstance_w(w_obj, space.w_int):
w_index = w_obj
else:
w_index = None
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -428,18 +428,12 @@
w_resulttype = space.type(w_result)
if space.is_w(w_resulttype, space.w_int):
return w_result
- elif space.is_w(w_resulttype, space.w_long):
- return space.hash(w_result)
elif space.is_true(space.isinstance(w_result, space.w_int)):
# be careful about subclasses of 'int'...
return space.wrap(space.int_w(w_result))
- elif space.is_true(space.isinstance(w_result, space.w_long)):
- # be careful about subclasses of 'long'...
- bigint = space.bigint_w(w_result)
- return space.wrap(bigint.hash())
else:
raise OperationError(space.w_TypeError,
- space.wrap("__hash__() should return an int or long"))
+ space.wrap("__hash__() should return an int"))
def userdel(space, w_obj):
w_del = space.lookup(w_obj, '__del__')
@@ -724,9 +718,8 @@
# more of the above manually-coded operations as well)
for targetname, specialname, checkerspec in [
- ('int', '__int__', ("space.w_int", "space.w_long")),
- ('index', '__index__', ("space.w_int", "space.w_long")),
- ('long', '__long__', ("space.w_int", "space.w_long")),
+ ('int', '__int__', ("space.w_int",)),
+ ('index', '__index__', ("space.w_int",)),
('float', '__float__', ("space.w_float",))]:
l = ["space.is_true(space.isinstance(w_result, %s))" % x
diff --git a/pypy/objspace/std/booltype.py b/pypy/objspace/std/booltype.py
--- a/pypy/objspace/std/booltype.py
+++ b/pypy/objspace/std/booltype.py
@@ -1,6 +1,6 @@
from pypy.interpreter import gateway
from pypy.objspace.std.stdtypedef import StdTypeDef
-from pypy.objspace.std.inttype import int_typedef
+from pypy.objspace.std.longtype import long_typedef
def descr__new__(space, w_booltype, w_obj=None):
space.w_bool.check_user_subclass(w_booltype)
@@ -11,7 +11,7 @@
# ____________________________________________________________
-bool_typedef = StdTypeDef("bool", int_typedef,
+bool_typedef = StdTypeDef("bool", long_typedef,
__doc__ = '''bool(x) -> bool
Returns True when the argument x is true, False otherwise.
diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -93,15 +93,13 @@
try:
value = ovfcheck_float_to_int(w_value.floatval)
except OverflowError:
- return space.long(w_value)
+ pass
else:
return space.newint(value)
-
-def long__Float(space, w_floatobj):
try:
- return W_LongObject.fromfloat(space, w_floatobj.floatval)
+ return W_LongObject.fromfloat(space, w_value.floatval)
except OverflowError:
- if isnan(w_floatobj.floatval):
+ if isnan(w_value.floatval):
raise OperationError(
space.w_ValueError,
space.wrap("cannot convert float NaN to integer"))
@@ -112,7 +110,7 @@
try:
value = ovfcheck_float_to_int(whole)
except OverflowError:
- return long__Float(space, w_floatobj)
+ return int__Float(space, w_floatobj)
else:
return space.newint(value)
diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -24,7 +24,7 @@
return False
if self.user_overridden_class or w_other.user_overridden_class:
return self is w_other
- return space.int_w(self) == space.int_w(w_other)
+ return space.bigint_w(self).eq(space.bigint_w(w_other))
def immutable_unique_id(self, space):
if self.user_overridden_class:
@@ -39,7 +39,7 @@
__slots__ = 'intval'
_immutable_fields_ = ['intval']
- from pypy.objspace.std.inttype import int_typedef as typedef
+ from pypy.objspace.std.longtype import long_typedef as typedef
def __init__(w_self, intval):
w_self.intval = intval
diff --git a/pypy/objspace/std/inttype.py b/pypy/objspace/std/inttype.py
--- a/pypy/objspace/std/inttype.py
+++ b/pypy/objspace/std/inttype.py
@@ -36,7 +36,7 @@
@gateway.unwrap_spec(s='bufferstr', byteorder=str)
def descr_from_bytes(space, w_cls, s, byteorder):
from pypy.objspace.std.longtype import descr_from_bytes
- return descr_from_bytes(space, space.w_long, s, byteorder)
+ return descr_from_bytes(space, space.w_int, s, byteorder)
def wrapint(space, x):
if space.config.objspace.std.withsmallint:
diff --git a/pypy/objspace/std/longobject.py b/pypy/objspace/std/longobject.py
--- a/pypy/objspace/std/longobject.py
+++ b/pypy/objspace/std/longobject.py
@@ -4,30 +4,12 @@
from pypy.objspace.std.model import registerimplementation, W_Object
from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.multimethod import FailedToImplementArgs
-from pypy.objspace.std.intobject import W_IntObject
+from pypy.objspace.std.intobject import W_IntObject, W_AbstractIntObject
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.rlib.rbigint import rbigint, SHIFT
-class W_AbstractLongObject(W_Object):
- __slots__ = ()
- def is_w(self, space, w_other):
- if not isinstance(w_other, W_AbstractLongObject):
- return False
- if self.user_overridden_class or w_other.user_overridden_class:
- return self is w_other
- return space.bigint_w(self).eq(space.bigint_w(w_other))
-
- def immutable_unique_id(self, space):
- if self.user_overridden_class:
- return None
- from pypy.objspace.std.model import IDTAG_LONG as tag
- b = space.bigint_w(self)
- b = b.lshift(3).or_(rbigint.fromint(tag))
- return space.newlong_from_rbigint(b)
-
-
-class W_LongObject(W_AbstractLongObject):
+class W_LongObject(W_AbstractIntObject):
"""This is a wrapper of rbigint."""
from pypy.objspace.std.longtype import long_typedef as typedef
_immutable_fields_ = ['num']
@@ -114,27 +96,18 @@
return W_LongObject.fromint(space, w_intobj.intval)
-# long__Long is supposed to do nothing, unless it has
+# int__Long is supposed to do nothing, unless it has
# a derived long object, where it should return
# an exact one.
-def long__Long(space, w_long1):
- if space.is_w(space.type(w_long1), space.w_long):
+def int__Long(space, w_long1):
+ if space.is_w(space.type(w_long1), space.w_int):
return w_long1
l = w_long1.num
return W_LongObject(l)
-trunc__Long = long__Long
-
-def long__Int(space, w_intobj):
- return space.newlong(w_intobj.intval)
-
-def int__Long(space, w_value):
- try:
- return space.newint(w_value.num.toint())
- except OverflowError:
- return long__Long(space, w_value)
+trunc__Long = int__Long
def index__Long(space, w_value):
- return long__Long(space, w_value)
+ return int__Long(space, w_value)
def float__Long(space, w_longobj):
try:
@@ -275,7 +248,7 @@
return W_LongObject(w_long1.num.neg())
def pos__Long(space, w_long):
- return long__Long(space, w_long)
+ return int__Long(space, w_long)
def abs__Long(space, w_long):
return W_LongObject(w_long.num.abs())
diff --git a/pypy/objspace/std/longtype.py b/pypy/objspace/std/longtype.py
--- a/pypy/objspace/std/longtype.py
+++ b/pypy/objspace/std/longtype.py
@@ -5,7 +5,7 @@
from pypy.objspace.std.strutil import string_to_bigint, ParseStringError
def descr_conjugate(space, w_int):
- return space.long(w_int)
+ return space.int(w_int)
def descr__new__(space, w_longtype, w_x=0, w_base=gateway.NoneNotWrapped):
@@ -20,7 +20,7 @@
if w_base is None:
# check for easy cases
if (W_SmallLongObject and type(w_value) is W_SmallLongObject
- and space.is_w(w_longtype, space.w_long)):
+ and space.is_w(w_longtype, space.w_int)):
return w_value
elif type(w_value) is W_LongObject:
return newbigint(space, w_longtype, w_value.num)
@@ -34,20 +34,13 @@
return string_to_w_long(space, w_longtype,
unicode_to_decimal_w(space, w_value))
else:
- # otherwise, use the __long__() or the __trunc__ methods
+ # otherwise, use the __int__() or the __trunc__ methods
w_obj = w_value
- if (space.lookup(w_obj, '__long__') is not None or
- space.lookup(w_obj, '__int__') is not None):
- w_obj = space.long(w_obj)
+ if space.lookup(w_obj, '__int__') is not None:
+ w_obj = space.int(w_obj)
else:
w_obj = space.trunc(w_obj)
- # :-( blame CPython 2.7
- if space.lookup(w_obj, '__long__') is not None:
- w_obj = space.long(w_obj)
- else:
- w_obj = space.int(w_obj)
- bigint = space.bigint_w(w_obj)
- return newbigint(space, w_longtype, bigint)
+ return w_obj
else:
base = space.int_w(w_base)
@@ -80,7 +73,7 @@
longobject.py, but takes an explicit w_longtype argument.
"""
if (space.config.objspace.std.withsmalllong
- and space.is_w(w_longtype, space.w_long)):
+ and space.is_w(w_longtype, space.w_int)):
try:
z = bigint.tolonglong()
except OverflowError:
@@ -94,13 +87,13 @@
return w_obj
def descr_get_numerator(space, w_obj):
- return space.long(w_obj)
+ return space.int(w_obj)
def descr_get_denominator(space, w_obj):
return space.newlong(1)
def descr_get_real(space, w_obj):
- return space.long(w_obj)
+ return space.int(w_obj)
def descr_get_imag(space, w_obj):
return space.newlong(0)
@@ -124,8 +117,8 @@
# ____________________________________________________________
-long_typedef = StdTypeDef("long",
- __doc__ = '''long(x[, base]) -> integer
+long_typedef = StdTypeDef("int",
+ __doc__ = '''int(x[, base]) -> integer
Convert a string or number to a long integer, if possible. A floating
point argument will be truncated towards zero (this does not include a
diff --git a/pypy/objspace/std/model.py b/pypy/objspace/std/model.py
--- a/pypy/objspace/std/model.py
+++ b/pypy/objspace/std/model.py
@@ -31,7 +31,7 @@
}
IDTAG_INT = 1
-IDTAG_LONG = 3
+#IDTAG_LONG = 3
IDTAG_FLOAT = 5
IDTAG_COMPLEX = 7
@@ -44,7 +44,7 @@
class result:
from pypy.objspace.std.objecttype import object_typedef
from pypy.objspace.std.booltype import bool_typedef
- from pypy.objspace.std.inttype import int_typedef
+ #from pypy.objspace.std.inttype import int_typedef
from pypy.objspace.std.floattype import float_typedef
from pypy.objspace.std.complextype import complex_typedef
from pypy.objspace.std.settype import set_typedef
@@ -184,8 +184,8 @@
(complexobject.W_ComplexObject,
complexobject.delegate_Bool2Complex),
]
self.typeorder[intobject.W_IntObject] += [
+ (longobject.W_LongObject, longobject.delegate_Int2Long),
(floatobject.W_FloatObject, floatobject.delegate_Int2Float),
- (longobject.W_LongObject, longobject.delegate_Int2Long),
(complexobject.W_ComplexObject,
complexobject.delegate_Int2Complex),
]
if config.objspace.std.withsmalllong:
diff --git a/pypy/objspace/std/smallintobject.py
b/pypy/objspace/std/smallintobject.py
--- a/pypy/objspace/std/smallintobject.py
+++ b/pypy/objspace/std/smallintobject.py
@@ -16,7 +16,7 @@
class W_SmallIntObject(W_AbstractIntObject, UnboxedValue):
__slots__ = 'intval'
- from pypy.objspace.std.inttype import int_typedef as typedef
+ from pypy.objspace.std.longtype import long_typedef as typedef
def unwrap(w_self, space):
return int(w_self.intval)
diff --git a/pypy/objspace/std/smalllongobject.py
b/pypy/objspace/std/smalllongobject.py
--- a/pypy/objspace/std/smalllongobject.py
+++ b/pypy/objspace/std/smalllongobject.py
@@ -9,7 +9,7 @@
from pypy.rlib.rarithmetic import r_longlong, r_int, r_uint
from pypy.rlib.rarithmetic import intmask, LONGLONG_BIT
from pypy.rlib.rbigint import rbigint
-from pypy.objspace.std.longobject import W_AbstractLongObject, W_LongObject
+from pypy.objspace.std.longobject import W_AbstractIntObject, W_LongObject
from pypy.objspace.std.intobject import W_IntObject
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.interpreter.error import OperationError
@@ -17,7 +17,7 @@
LONGLONG_MIN = r_longlong((-1) << (LONGLONG_BIT-1))
-class W_SmallLongObject(W_AbstractLongObject):
+class W_SmallLongObject(W_AbstractIntObject):
from pypy.objspace.std.longtype import long_typedef as typedef
_immutable_fields_ = ['longlong']
@@ -109,9 +109,6 @@
return space.newcomplex(float(w_small.longlong), 0.0)
-def long__SmallLong(space, w_value):
- return w_value
-
def int__SmallLong(space, w_value):
a = w_value.longlong
b = intmask(a)
diff --git a/pypy/objspace/std/test/test_intobject.py
b/pypy/objspace/std/test/test_intobject.py
--- a/pypy/objspace/std/test/test_intobject.py
+++ b/pypy/objspace/std/test/test_intobject.py
@@ -314,10 +314,7 @@
def test_int_string(self):
assert 42 == int("42")
- assert 10000000000 == long("10000000000")
-
- def test_int_unicode(self):
- assert 42 == int(unicode('42'))
+ assert 10000000000 == int("10000000000")
def test_int_float(self):
assert 4 == int(4.2)
@@ -348,7 +345,7 @@
def test_overflow(self):
import sys
n = sys.maxint + 1
- assert isinstance(n, long)
+ assert isinstance(n, int)
def test_pow(self):
assert pow(2, -10) == 1/1024.
@@ -369,8 +366,6 @@
assert j("100") == 100
assert j("100",2) == 4
assert isinstance(j("100",2),j)
- raises(OverflowError,j,sys.maxint+1)
- raises(OverflowError,j,str(sys.maxint+1))
def test_int_subclass_ops(self):
import sys
@@ -402,7 +397,7 @@
assert (5 + j(100), type(5 + j(100))) == ( 105, int)
assert (5 - j(100), type(5 - j(100))) == ( -95, int)
assert (5 * j(100), type(5 * j(100))) == ( 500, int)
- assert (5 << j(100), type(5 << j(100))) == (5 << 100, long)
+ assert (5 << j(100), type(5 << j(100))) == (5 << 100, int)
assert (j(100) >> 2, type(j(100) >> 2)) == ( 25, int)
def test_int_subclass_int(self):
@@ -413,17 +408,15 @@
return '<instance of j>'
class subint(int):
pass
- class sublong(long):
- pass
value = 42L
assert int(j()) == 42
value = 4200000000000000000000000000000000L
assert int(j()) == 4200000000000000000000000000000000L
value = subint(42)
assert int(j()) == 42 and type(int(j())) is subint
- value = sublong(4200000000000000000000000000000000L)
+ value = subint(4200000000000000000000000000000000L)
assert (int(j()) == 4200000000000000000000000000000000L
- and type(int(j())) is sublong)
+ and type(int(j())) is subint)
value = 42.0
raises(TypeError, int, j())
value = "foo"
@@ -444,16 +437,16 @@
def test_special_long(self):
class a(object):
- def __long__(self):
+ def __int__(self):
self.ar = True
return None
inst = a()
- raises(TypeError, long, inst)
+ raises(TypeError, int, inst)
assert inst.ar == True
class b(object):
pass
- raises((AttributeError,TypeError), long, b())
+ raises((AttributeError,TypeError), int, b())
def test_just_trunc(self):
class myint(object):
diff --git a/pypy/objspace/std/test/test_longobject.py
b/pypy/objspace/std/test/test_longobject.py
--- a/pypy/objspace/std/test/test_longobject.py
+++ b/pypy/objspace/std/test/test_longobject.py
@@ -63,7 +63,7 @@
assert x * 2 ** 40 == x << 40
def test_truediv(self):
- exec "from __future__ import division; a = 31415926L / 10000000L"
+ a = 31415926L / 10000000L
assert a == 3.1415926
def test_floordiv(self):
@@ -155,22 +155,22 @@
assert not (int(BIG)-1 >= BIG)
def test_conversion(self):
- class long2(long):
+ class long2(int):
pass
x = 1L
x = long2(x<<100)
y = int(x)
- assert type(y) == long
- assert type(+long2(5)) is long
- assert type(long2(5) << 0) is long
- assert type(long2(5) >> 0) is long
- assert type(long2(5) + 0) is long
- assert type(long2(5) - 0) is long
- assert type(long2(5) * 1) is long
- assert type(1 * long2(5)) is long
- assert type(0 + long2(5)) is long
- assert type(-long2(0)) is long
- assert type(long2(5) // 1) is long
+ assert type(y) == int
+ assert type(+long2(5)) is int
+ assert type(long2(5) << 0) is int
+ assert type(long2(5) >> 0) is int
+ assert type(long2(5) + 0) is int
+ assert type(long2(5) - 0) is int
+ assert type(long2(5) * 1) is int
+ assert type(1 * long2(5)) is int
+ assert type(0 + long2(5)) is int
+ assert type(-long2(0)) is int
+ assert type(long2(5) // 1) is int
def test_pow(self):
x = 0L
@@ -194,7 +194,7 @@
assert y < r <= 0
for x in [-1L, 0L, 1L, 2L ** 100 - 1, -2L ** 100 - 1]:
for y in [-105566530L, -1L, 1L, 1034522340L]:
- print "checking division for %s, %s" % (x, y)
+ print("checking division for %s, %s" % (x, y))
check_division(x, y)
# special case from python tests:
s1 = 33
@@ -209,7 +209,7 @@
raises(ZeroDivisionError, "x // 0L")
def test_format(self):
- assert repr(12345678901234567890) == '12345678901234567890L'
+ assert repr(12345678901234567890) == '12345678901234567890'
assert str(12345678901234567890) == '12345678901234567890'
assert hex(0x1234567890ABCDEFL) == '0x1234567890abcdefL'
assert oct(01234567012345670L) == '01234567012345670L'
@@ -227,7 +227,7 @@
def test_hash(self):
# ints have the same hash as equal longs
for i in range(-4, 14):
- assert hash(i) == hash(long(i))
+ assert hash(i) == hash(int(i))
# might check too much -- it's ok to change the hashing algorithm
assert hash(123456789L) == 123456789
assert hash(1234567890123456789L) in (
@@ -247,8 +247,8 @@
def test_long(self):
import sys
n = -sys.maxint-1
- assert long(n) == n
- assert str(long(n)) == str(n)
+ assert int(n) == n
+ assert str(int(n)) == str(n)
def test_huge_longs(self):
import operator
@@ -262,45 +262,41 @@
class myint(object):
def __trunc__(self):
return 42
- assert long(myint()) == 42
+ assert int(myint()) == 42
- def test_override___long__(self):
- class mylong(long):
- def __long__(self):
+ def test_override___int__(self):
+ class myint(int):
+ def __int__(self):
return 42L
- assert long(mylong(21)) == 42L
- class myotherlong(long):
+ assert int(myint(21)) == 42L
+ class myotherint(int):
pass
- assert long(myotherlong(21)) == 21L
+ assert int(myotherint(21)) == 21L
- def test___long__(self):
+ def test___int__(self):
class A(object):
- def __long__(self):
- return 42
- assert long(A()) == 42L
- class B(object):
def __int__(self):
return 42
- raises(TypeError, long, B())
+ assert int(A()) == 42L
# but!: (blame CPython 2.7)
class Integral(object):
def __int__(self):
return 42
- class TruncReturnsNonLong(object):
+ class TruncReturnsNonInt(object):
def __trunc__(self):
return Integral()
- assert long(TruncReturnsNonLong()) == 42
+ assert int(TruncReturnsNonInt()) == 42
def test_conjugate(self):
assert (7L).conjugate() == 7L
assert (-7L).conjugate() == -7L
- class L(long):
+ class L(int):
pass
- assert type(L(7).conjugate()) is long
+ assert type(L(7).conjugate()) is int
- class L(long):
+ class L(int):
def __pos__(self):
return 43
assert L(7).conjugate() == 7L
@@ -311,27 +307,14 @@
assert ((2**31)-1).bit_length() == 31
def test_from_bytes(self):
- assert long.from_bytes(b'c', 'little') == 99
- assert long.from_bytes(b'\x01\x01', 'little') == 257
+ assert int.from_bytes(b'c', 'little') == 99
+ assert int.from_bytes(b'\x01\x01', 'little') == 257
def test_negative_zero(self):
x = eval("-0L")
assert x == 0L
- def test_mix_int_and_long(self):
- class IntLongMixClass(object):
- def __int__(self):
- return 42L
-
- def __long__(self):
- return 64
-
- mixIntAndLong = IntLongMixClass()
- as_long = long(mixIntAndLong)
- assert type(as_long) is long
- assert as_long == 64
-
def test_long_real(self):
- class A(long): pass
+ class A(int): pass
b = A(5).real
- assert type(b) is long
+ assert type(b) is int
diff --git a/pypy/objspace/std/test/test_newformat.py
b/pypy/objspace/std/test/test_newformat.py
--- a/pypy/objspace/std/test/test_newformat.py
+++ b/pypy/objspace/std/test/test_newformat.py
@@ -269,12 +269,6 @@
cls.w_i = cls.space.w_int
-class AppTestLongFormatting(BaseIntegralFormattingTest):
-
- def setup_class(cls):
- cls.w_i = cls.space.w_long
-
-
class AppTestFloatFormatting:
def setup_class(cls):
cls.space = gettestobjspace(usemodules=('_locale',))
diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -293,7 +293,7 @@
return _format(self, digits, prefix, suffix)
def repr(self):
- return _format(self, BASE10, '', 'L')
+ return _format(self, BASE10)
def str(self):
return _format(self, BASE10)
diff --git a/pypy/translator/geninterplevel.py
b/pypy/translator/geninterplevel.py
--- a/pypy/translator/geninterplevel.py
+++ b/pypy/translator/geninterplevel.py
@@ -844,7 +844,7 @@
typename_mapping = {
object: 'space.w_object',
int: 'space.w_int',
- long: 'space.w_long',
+ long: 'space.w_int',
bool: 'space.w_bool',
list: 'space.w_list',
tuple: 'space.w_tuple',
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit