Author: Manuel Jacob
Branch: py3k
Changeset: r61366:a8df5c23b131
Date: 2013-02-16 18:52 +0100
http://bitbucket.org/pypy/pypy/changeset/a8df5c23b131/
Log: Raise the right error if int() is called with a base that doesn't
fit into the machine's long int type.
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
@@ -48,7 +48,12 @@
bigint = space.bigint_w(w_obj)
return newbigint(space, w_longtype, bigint)
else:
- base = space.int_w(w_base)
+ try:
+ base = space.int_w(w_base)
+ except OperationError, e:
+ if not e.match(space, space.w_OverflowError):
+ raise
+ base = 37 # this raises the right error in string_to_bigint()
if space.isinstance_w(w_value, space.w_unicode):
from pypy.objspace.std.unicodeobject import unicode_to_decimal_w
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
@@ -340,3 +340,6 @@
assert 'hello àèìò' in e.message
else:
assert False, 'did not raise'
+
+ def test_base_overflow(self):
+ raises(ValueError, int, '42', 2**63)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit