Author: Carl Friedrich Bolz <cfb...@gmx.de>
Branch: py3.5
Changeset: r88801:b93629909a8f
Date: 2016-12-01 18:02 +0100
http://bitbucket.org/pypy/pypy/changeset/b93629909a8f/

Log:    make sure that fromfile does not emit a warning

diff --git a/pypy/module/_rawffi/array.py b/pypy/module/_rawffi/array.py
--- a/pypy/module/_rawffi/array.py
+++ b/pypy/module/_rawffi/array.py
@@ -185,7 +185,7 @@
 
     def setslice(self, space, w_slice, w_value):
         start, stop = self.decodeslice(space, w_slice)
-        value = space.str_w(w_value)
+        value = space.bytes_w(w_value)
         if start + len(value) != stop:
             raise oefmt(space.w_ValueError, "cannot resize array")
         ll_buffer = self.ll_buffer
diff --git a/pypy/module/array/interp_array.py 
b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -308,7 +308,7 @@
         """ fromfile(f, n)
 
         Read n objects from the file object f and append them to the end of the
-        array.  Also called as read.
+        array.
         """
         try:
             size = ovfcheck(self.itemsize * n)
@@ -323,7 +323,7 @@
                 item = item[0:elems]
             self._frombytes(space, item)
             raise oefmt(space.w_EOFError, "not enough items in file")
-        self.descr_fromstring(space, w_item)
+        self._frombytes(space, item)
 
     def descr_tofile(self, space, w_f):
         """ tofile(f)
diff --git a/pypy/module/array/test/test_array.py 
b/pypy/module/array/test/test_array.py
--- a/pypy/module/array/test/test_array.py
+++ b/pypy/module/array/test/test_array.py
@@ -227,6 +227,19 @@
             raises(EOFError, a.fromfile, myfile(b'\x01', 2 + i), 2)
             assert len(a) == 1 and a[0] == 257
 
+    def test_fromfile_no_warning(self):
+        import warnings
+        # check that fromfile defers to frombytes, not fromstring
+        class FakeF(object):
+            def read(self, n):
+                return b"a" * n
+        a = self.array('b')
+        with warnings.catch_warnings(record=True) as w:
+            # Cause all warnings to always be triggered.
+            warnings.simplefilter("always")
+            a.fromfile(FakeF(), 4)
+            assert len(w) == 0
+
     def test_fromlist(self):
         a = self.array('b')
         raises(OverflowError, a.fromlist, [1, 2, 400])
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to