[pypy-commit] pypy py3.6: Add support for FsPath to os.unlink()
amauryfa
pypy.commits at gmail.com
Tue Jan 1 12:51:36 EST 2019
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3.6
Changeset: r95558:77d2a71504df
Date: 2019-01-01 18:44 +0100
http://bitbucket.org/pypy/pypy/changeset/77d2a71504df/
Log: Add support for FsPath to os.unlink()
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
@@ -727,8 +727,9 @@
else:
return space.newint(rc)
- at unwrap_spec(dir_fd=DirFD(rposix.HAVE_UNLINKAT))
-def unlink(space, w_path, __kwonly__, dir_fd=DEFAULT_DIR_FD):
+ at unwrap_spec(path=path_or_fd(allow_fd=False),
+ dir_fd=DirFD(rposix.HAVE_UNLINKAT))
+def unlink(space, path, __kwonly__, dir_fd=DEFAULT_DIR_FD):
"""unlink(path, *, dir_fd=None)
Remove a file (same as remove()).
@@ -739,15 +740,16 @@
If it is unavailable, using it will raise a NotImplementedError."""
try:
if rposix.HAVE_UNLINKAT and dir_fd != DEFAULT_DIR_FD:
- path = space.fsencode_w(w_path)
- rposix.unlinkat(path, dir_fd, removedir=False)
+ rposix.unlinkat(space.fsencode_w(path.w_path),
+ dir_fd, removedir=False)
else:
- dispatch_filename(rposix.unlink)(space, w_path)
+ call_rposix(rposix.unlink, path)
except OSError as e:
- raise wrap_oserror2(space, e, w_path, eintr_retry=False)
+ raise wrap_oserror2(space, e, path.w_path, eintr_retry=False)
- at unwrap_spec(dir_fd=DirFD(rposix.HAVE_UNLINKAT))
-def remove(space, w_path, __kwonly__, dir_fd=DEFAULT_DIR_FD):
+ at unwrap_spec(path=path_or_fd(allow_fd=False),
+ dir_fd=DirFD(rposix.HAVE_UNLINKAT))
+def remove(space, path, __kwonly__, dir_fd=DEFAULT_DIR_FD):
"""remove(path, *, dir_fd=None)
Remove a file (same as unlink()).
@@ -758,12 +760,12 @@
If it is unavailable, using it will raise a NotImplementedError."""
try:
if rposix.HAVE_UNLINKAT and dir_fd != DEFAULT_DIR_FD:
- path = space.fsencode_w(w_path)
- rposix.unlinkat(path, dir_fd, removedir=False)
+ rposix.unlinkat(space.fsencode_w(path.w_path),
+ dir_fd, removedir=False)
else:
- dispatch_filename(rposix.unlink)(space, w_path)
+ call_rposix(rposix.unlink, path)
except OSError as e:
- raise wrap_oserror2(space, e, w_path, eintr_retry=False)
+ raise wrap_oserror2(space, e, path.w_path, eintr_retry=False)
def _getfullpathname(space, w_path):
"""helper for ntpath.abspath """
@@ -1109,9 +1111,9 @@
wrap_oserror(space, e, eintr_retry=True)
@unwrap_spec(src_dir_fd=DirFD(rposix.HAVE_RENAMEAT),
- dst_dir_fd=DirFD(rposix.HAVE_RENAMEAT))
+ dst_dir_fd=DirFD(rposix.HAVE_RENAMEAT))
def rename(space, w_src, w_dst, __kwonly__,
- src_dir_fd=DEFAULT_DIR_FD, dst_dir_fd=DEFAULT_DIR_FD):
+ src_dir_fd=DEFAULT_DIR_FD, dst_dir_fd=DEFAULT_DIR_FD):
"""rename(src, dst, *, src_dir_fd=None, dst_dir_fd=None)
Rename a file or directory.
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
@@ -390,6 +390,16 @@
if sys.platform != "win32":
assert posix.access(pdir, posix.X_OK) is False
+ def test_unlink(self):
+ os = self.posix
+ path = self.path
+ with open(path, 'wb'):
+ pass
+ class Path:
+ def __fspath__(self):
+ return path
+ os.unlink(Path())
+
def test_times(self):
"""
posix.times() should return a posix.times_result object giving
More information about the pypy-commit
mailing list