Commits

Alex Gaynor committed 21b2854

Allow io.BytesIO to be instantiated with kwargs.

  • Participants
  • Parent commits 0fb4abd

Comments (0)

Files changed (2)

pypy/module/_io/interp_bytesio.py

         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):
     __getstate__ = interp2app(W_BytesIO.getstate_w),
     __setstate__ = interp2app(W_BytesIO.setstate_w),
     )
-

pypy/module/_io/test/test_bytesio.py

         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()