[pypy-commit] pypy py3k: fix an obscure bytes() bug

pjenvey noreply at buildbot.pypy.org
Sat Nov 17 23:50:19 CET 2012


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r58979:920e45d66e05
Date: 2012-11-17 14:51 -0800
http://bitbucket.org/pypy/pypy/changeset/920e45d66e05/

Log:	fix an obscure bytes() bug

diff --git a/pypy/objspace/std/stringtype.py b/pypy/objspace/std/stringtype.py
--- a/pypy/objspace/std/stringtype.py
+++ b/pypy/objspace/std/stringtype.py
@@ -312,7 +312,7 @@
 
     w_bytes_method = space.lookup(w_source, "__bytes__")
     if w_bytes_method:
-        w_bytes = space.call_function(w_bytes_method, w_source)
+        w_bytes = space.get_and_call_function(w_bytes_method, w_source)
         w_source = w_bytes
 
     # sequence of bytes
diff --git a/pypy/objspace/std/test/test_stringobject.py b/pypy/objspace/std/test/test_stringobject.py
--- a/pypy/objspace/std/test/test_stringobject.py
+++ b/pypy/objspace/std/test/test_stringobject.py
@@ -704,6 +704,12 @@
                 return b"bytes"
         assert bytes(S()) == b"bytes"
 
+        class X:
+            __bytes__ = property(lambda self: self.bytes)
+            def bytes(self):
+                return b'pyramid'
+        assert bytes(X()) == b'pyramid'
+
     def test_getnewargs(self):
         assert  b"foo".__getnewargs__() == (b"foo",)
 


More information about the pypy-commit mailing list