[pypy-commit] pypy py3.5-byteformat: bytearray can now be formatted by %b
plan_rich
pypy.commits at gmail.com
Wed Aug 31 05:27:21 EDT 2016
Author: Richard Plangger <planrichi at gmail.com>
Branch: py3.5-byteformat
Changeset: r86772:cb92a4ecf35d
Date: 2016-08-31 11:26 +0200
http://bitbucket.org/pypy/pypy/changeset/cb92a4ecf35d/
Log: bytearray can now be formatted by %b
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
@@ -484,7 +484,9 @@
self.std_wp(space.bytes_w(w_value))
return
if space.isinstance_w(w_value, space.w_bytearray):
- self.std_wp(space.bytes_w(w_value))
+ buf = w_value.buffer_w(space, 0)
+ # convert the array of the buffer to a py 2 string
+ self.std_wp(buf.as_str())
return
w_bytes_method = space.lookup(w_value, "__bytes__")
diff --git a/pypy/objspace/std/test/test_bytesobject.py b/pypy/objspace/std/test/test_bytesobject.py
--- a/pypy/objspace/std/test/test_bytesobject.py
+++ b/pypy/objspace/std/test/test_bytesobject.py
@@ -889,5 +889,6 @@
assert b'%b' % u'はい'.encode('utf-8') == u'はい'.encode('utf-8')
raises(TypeError, 'b"%b" % 3.14')
raises(TypeError, 'b"%b" % "hello world"')
+ assert b'%b %b' % (b'a', bytearray(b'f f e')) == b'a f f e'
"""
More information about the pypy-commit
mailing list