[pypy-commit] pypy py3.7: the weird behaviour was fixed in 3.7

cfbolz pypy.commits at gmail.com
Mon Feb 3 12:00:12 EST 2020


Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: py3.7
Changeset: r98647:784f031646b7
Date: 2020-02-03 14:43 +0100
http://bitbucket.org/pypy/pypy/changeset/784f031646b7/

Log:	the weird behaviour was fixed in 3.7

diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -982,15 +982,21 @@
   If this functionality is unavailable, using it raises NotImplementedError."""
     if space.is_none(w_path):
         w_path = space.newtext(".")
-    if space.isinstance_w(w_path, space.w_bytes):
-        # XXX CPython doesn't follow this path either if w_path is,
-        # for example, a memoryview or another buffer type
-        dirname = space.bytes0_w(w_path)
+    try:
+        dirname = space.bytesbuf0_w(w_path)
+    except OperationError as e:
+        if not e.match(space, space.w_TypeError):
+            raise
+    else:
+        if not space.isinstance_w(w_path, space.w_bytes):
+            # use fsencode to get the correct warning
+            space.fsencode_w(w_path)
         try:
             result = rposix.listdir(dirname)
         except OSError as e:
             raise wrap_oserror2(space, e, w_path, eintr_retry=False)
         return space.newlist_bytes(result)
+
     try:
         path = space.fsencode_w(w_path)
     except OperationError as operr:
diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -364,26 +364,13 @@
         expected = b'caf%E9' if sys.platform == 'darwin' else b'caf\xe9'
         assert expected in result
 
-    def test_listdir_memoryview_returns_unicode(self):
+    def test_listdir_memoryview_returns_bytes(self):
         import sys
-        # XXX unknown why CPython has this behaviour
-
-        # avoid importing stdlib os, copy fsencode instead
-        def fsencode(filename):
-            encoding = sys.getfilesystemencoding()
-            errors = sys.getfilesystemencodeerrors()
-            filename = posix.fspath(filename)  # Does type-checking of `filename`.
-            if isinstance(filename, str):
-                return filename.encode(encoding, errors)
-            else:
-                return filename
-
-
         bytes_dir = self.bytes_dir
         posix = self.posix
         result1 = posix.listdir(bytes_dir)              # -> list of bytes
-        result2 = posix.listdir(memoryview(bytes_dir))  # -> list of unicodes
-        assert [fsencode(x) for x in result2] == result1
+        result2 = posix.listdir(memoryview(bytes_dir))  # -> list of bytes
+        assert result2 == result1
 
     @py.test.mark.skipif("sys.platform == 'win32'")
     def test_fdlistdir(self):


More information about the pypy-commit mailing list