Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r90222:549b113c75b6
Date: 2017-02-20 11:14 +0100
http://bitbucket.org/pypy/pypy/changeset/549b113c75b6/

Log:    fix error message

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
@@ -72,7 +72,7 @@
 
     def fmt_X(self, w_value):
         "HEX formatting"
-        r = hex_num_helper(self.space, w_value)
+        r = hex_num_helper(self.space, w_value, fmt_for_error='%X')
         if self.f_alt:
             prefix = '0X'
         else:
@@ -618,14 +618,14 @@
 
 def format_num_helper_generator(fmt, digits, decoder=maybe_int,
                                 expect_text="a number"):
-    def format_num_helper(space, w_value):
+    def format_num_helper(space, w_value, fmt_for_error=fmt):
         if not space.isinstance_w(w_value, space.w_int):
             try:
                 w_value = decoder(space, w_value)
             except OperationError:
                 raise oefmt(space.w_TypeError,
                             "%s format: %s is required, not %T",
-                            fmt, expect_text, w_value)
+                            fmt_for_error, expect_text, 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
@@ -82,8 +82,10 @@
         assert '-23' == '%d' % f
         assert '-23' == '%i' % f
         assert '-23' == '%u' % f
-        raises(TypeError, "'%x' % f")
-        raises(TypeError, "'%X' % f")
+        e = raises(TypeError, "'%x' % f")
+        assert str(e.value).startswith("%x format:")
+        e = raises(TypeError, "'%X' % f")
+        assert str(e.value).startswith("%X format:")
         raises(TypeError, "'%o' % f")
         assert '-23.456' == '%s' % f
         # for 'r' use a float that has an exact decimal rep:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to