[pypy-commit] pypy stdlib-2.7.4: Merged in chrish42/pypy/stdlib-2.7.4 (pull request #181)
pjenvey
noreply at buildbot.pypy.org
Wed Aug 14 02:24:05 CEST 2013
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: stdlib-2.7.4
Changeset: r66140:97fee6f50a83
Date: 2013-08-13 17:23 -0700
http://bitbucket.org/pypy/pypy/changeset/97fee6f50a83/
Log: Merged in chrish42/pypy/stdlib-2.7.4 (pull request #181)
In string formatting, if conversion to a number with __int__()
fails, we should retry with __long__()
diff --git a/pypy/objspace/std/formatting.py b/pypy/objspace/std/formatting.py
--- a/pypy/objspace/std/formatting.py
+++ b/pypy/objspace/std/formatting.py
@@ -543,7 +543,10 @@
def format_num_helper_generator(fmt, digits):
def format_num_helper(space, w_value):
- w_value = maybe_int(space, w_value)
+ try:
+ w_value = maybe_int(space, w_value)
+ except OperationError:
+ w_value = space.long(w_value)
try:
value = space.int_w(w_value)
return fmt % (value,)
diff --git a/pypy/objspace/std/test/test_stringformat.py b/pypy/objspace/std/test/test_stringformat.py
--- a/pypy/objspace/std/test/test_stringformat.py
+++ b/pypy/objspace/std/test/test_stringformat.py
@@ -186,6 +186,16 @@
def test_broken_unicode(self):
raises(UnicodeDecodeError, 'Názov: %s'.__mod__, u'Jerry')
+ def test_format_retry_with_long_if_int_fails(self):
+ class IntFails(object):
+ def __int__(self):
+ raise Exception
+ def __long__(self):
+ return 0L
+
+ assert "%x" % IntFails() == '0'
+
+
class AppTestWidthPrec:
def test_width(self):
a = 'a'
More information about the pypy-commit
mailing list