[pypy-commit] pypy py3.5: DeprecationWarning when opening in 'U' mode

arigo pypy.commits at gmail.com
Thu Jan 12 08:53:53 EST 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r89505:623575878821
Date: 2017-01-12 14:53 +0100
http://bitbucket.org/pypy/pypy/changeset/623575878821/

Log:	DeprecationWarning when opening in 'U' mode

diff --git a/pypy/module/_io/interp_io.py b/pypy/module/_io/interp_io.py
--- a/pypy/module/_io/interp_io.py
+++ b/pypy/module/_io/interp_io.py
@@ -67,8 +67,13 @@
     if updating:
         rawmode += "+"
 
-    if universal and (writing or appending):
-        raise oefmt(space.w_ValueError, "can't use U and writing mode at once")
+    if universal:
+        if writing or appending:
+            raise oefmt(space.w_ValueError,
+                        "can't use U and writing mode at once")
+        space.warn(space.wrap("'U' mode is deprecated ('r' has the same "
+                              "effect in Python 3.x)"),
+                   space.w_DeprecationWarning)
     if text and binary:
         raise oefmt(space.w_ValueError,
                     "can't have text and binary mode at once")
diff --git a/pypy/module/_io/test/test_io.py b/pypy/module/_io/test/test_io.py
--- a/pypy/module/_io/test/test_io.py
+++ b/pypy/module/_io/test/test_io.py
@@ -225,17 +225,21 @@
 
     def test_attributes(self):
         import _io
+        import warnings
 
         with _io.open(self.tmpfile, "wb", buffering=0) as f:
             assert f.mode == "wb"
 
-        with _io.open(self.tmpfile, "U") as f:
-            assert f.name == self.tmpfile
-            assert f.buffer.name == self.tmpfile
-            assert f.buffer.raw.name == self.tmpfile
-            assert f.mode == "U"
-            assert f.buffer.mode == "rb"
-            assert f.buffer.raw.mode == "rb"
+        with warnings.catch_warnings(record=True) as l:
+            warnings.simplefilter("always")
+            with _io.open(self.tmpfile, "U") as f:
+                assert f.name == self.tmpfile
+                assert f.buffer.name == self.tmpfile
+                assert f.buffer.raw.name == self.tmpfile
+                assert f.mode == "U"
+                assert f.buffer.mode == "rb"
+                assert f.buffer.raw.mode == "rb"
+        assert isinstance(l[0].message, DeprecationWarning)
 
         with _io.open(self.tmpfile, "w+") as f:
             assert f.mode == "w+"


More information about the pypy-commit mailing list