[pypy-commit] pypy unicode-utf8-py3: test, fix for '%c' % uchr

mattip pypy.commits at gmail.com
Sun Dec 2 11:52:18 EST 2018


Author: Matti Picus <matti.picus at gmail.com>
Branch: unicode-utf8-py3
Changeset: r95403:8d78ef00bde9
Date: 2018-12-02 08:38 -0800
http://bitbucket.org/pypy/pypy/changeset/8d78ef00bde9/

Log:	test, fix for '%c' % uchr

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
@@ -499,7 +499,7 @@
             else:
                 if space.isinstance_w(w_value, space.w_unicode):
                     ustr = space.utf8_w(w_value)
-                    if len(ustr) == 1:
+                    if space.len_w(w_value) == 1:
                         self.std_wp(ustr)
                         return
                 raise oefmt(space.w_TypeError, "%c requires int or char")
diff --git a/pypy/objspace/std/test/test_unicodeobject.py b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -997,6 +997,9 @@
         assert type(s) is str
         assert s == '\u1234'
 
+    def test_formatting_uchr(self):
+        assert '%c' % '\U00021483' == '\U00021483'
+
     def test_formatting_unicode__str__(self):
         class A:
             def __init__(self, num):


More information about the pypy-commit mailing list