[pypy-svn] pypy default: Allow io.BytesIO to be instantiated with kwargs.

alex_gaynor commits-noreply at bitbucket.org
Fri Jan 28 23:52:29 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r41438:21b2854c211a
Date: 2011-01-28 17:52 -0500
http://bitbucket.org/pypy/pypy/changeset/21b2854c211a/

Log:	Allow io.BytesIO to be instantiated with kwargs.

diff --git a/pypy/module/_io/test/test_bytesio.py b/pypy/module/_io/test/test_bytesio.py
--- a/pypy/module/_io/test/test_bytesio.py
+++ b/pypy/module/_io/test/test_bytesio.py
@@ -8,6 +8,14 @@
         import _io
         raises(TypeError, _io.BytesIO, u"12345")
 
+    def test_init_kwargs(self):
+        import _io
+
+        buf = "1234567890"
+        b = _io.BytesIO(initial_bytes=buf)
+        assert b.read() == buf
+        raises(TypeError, _io.BytesIO, buf, foo=None)
+
     def test_capabilities(self):
         import _io
         f = _io.BytesIO()

diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py
--- a/pypy/module/_io/interp_bytesio.py
+++ b/pypy/module/_io/interp_bytesio.py
@@ -23,14 +23,14 @@
         self.buf = None
 
     @unwrap_spec('self', ObjSpace, W_Root)
-    def descr_init(self, space, w_initvalue=None):
+    def descr_init(self, space, w_initial_bytes=None):
         # In case __init__ is called multiple times
         self.buf = []
         self.string_size = 0
         self.pos = 0
 
-        if not space.is_w(w_initvalue, space.w_None):
-            self.write_w(space, w_initvalue)
+        if not space.is_w(w_initial_bytes, space.w_None):
+            self.write_w(space, w_initial_bytes)
             self.pos = 0
 
     def _check_closed(self, space, message=None):
@@ -228,4 +228,3 @@
     __getstate__ = interp2app(W_BytesIO.getstate_w),
     __setstate__ = interp2app(W_BytesIO.setstate_w),
     )
-


More information about the Pypy-commit mailing list