Skip to content

Commit 06aebeb

Browse files
committed
Remove lchown(), don't expose dir_fd
1 parent f9a611b commit 06aebeb

File tree

4 files changed

+6
-45
lines changed

4 files changed

+6
-45
lines changed

Doc/library/pathlib.rst

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -755,13 +755,13 @@ call fails (for example because the path doesn't exist).
755755
.. versionchanged:: 3.10
756756
The *follow_symlinks* parameter was added.
757757

758-
.. method:: Path.chown(uid, gid, *, dir_fd=None, follow_symlinks=True)
758+
.. method:: Path.chown(uid, gid, *, follow_symlinks=True)
759759

760760
Change the file ownership, like :func:`os.chown`.
761761

762762
This method normally follows symlinks. Some Unix flavours support changing
763763
permissions on the symlink itself; on these platforms you may add the
764-
argument ``follow_symlinks=False``, or use :meth:`~Path.lchown`.
764+
argument ``follow_symlinks=False``.
765765

766766
::
767767

@@ -947,14 +947,6 @@ call fails (for example because the path doesn't exist).
947947
symbolic link's mode is changed rather than its target's.
948948

949949

950-
.. method:: Path.lchown(uid, gid, *, dir_fd=None)
951-
952-
Like :meth:`Path.chown`, but if the path points to a symbolic link, the
953-
symbolic link's mode is changed rather than its target's.
954-
955-
.. availability:: Unix.
956-
957-
958950
.. method:: Path.lstat()
959951

960952
Like :meth:`Path.stat`, but if the path points to a symbolic link, return

Lib/pathlib.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,18 +1127,11 @@ def lchmod(self, mode):
11271127
"""
11281128
self.chmod(mode, follow_symlinks=False)
11291129

1130-
def chown(self, uid, gid, *, dir_fd=None, follow_symlinks=True):
1130+
def chown(self, uid, gid, *, follow_symlinks=True):
11311131
"""
11321132
Change the owner and group id of path to the numeric uid and gid, like os.chown().
11331133
"""
1134-
os.chown(self, uid, gid, dir_fd=dir_fd, follow_symlinks=follow_symlinks)
1135-
1136-
def lchown(self, uid, gid, *, dir_fd=None):
1137-
"""
1138-
Like chown(), except if the path points to a symlink, the symlink's
1139-
permissions are changed, rather than its target's.
1140-
"""
1141-
self.chown(uid, gid, dir_fd=dir_fd, follow_symlinks=False)
1134+
os.chown(self, uid, gid, follow_symlinks=follow_symlinks)
11421135

11431136
def unlink(self, missing_ok=False):
11441137
"""
@@ -1407,8 +1400,5 @@ class WindowsPath(Path, PureWindowsPath):
14071400
def is_mount(self):
14081401
raise NotImplementedError("Path.is_mount() is unsupported on this system")
14091402

1410-
def chown(self, uid, gid, *, dir_fd=None, follow_symlinks=True):
1403+
def chown(self, uid, gid, *, follow_symlinks=True):
14111404
raise NotImplementedError("Path.chown() is unsupported on this system")
1412-
1413-
def lchown(self, uid, gid, *, dir_fd=None):
1414-
raise NotImplementedError("Path.lchown() is unsupported on this system")

Lib/test/test_pathlib.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,26 +1926,6 @@ def test_chown_windows(self):
19261926
new_gid = 503
19271927
with self.assertRaises(NotImplementedError):
19281928
p.chown(uid=new_uid, gid=new_gid)
1929-
1930-
@only_posix
1931-
@mock.patch('pathlib.Path.chown')
1932-
def test_lchown(self, chown_mock):
1933-
new_uid = 503
1934-
new_gid = 503
1935-
1936-
p = self.cls(BASE) / 'fileA'
1937-
1938-
p.lchown(new_uid, new_gid)
1939-
chown_mock.assert_called_with(new_uid, new_gid, dir_fd=None, follow_symlinks=False)
1940-
1941-
@only_nt
1942-
def test_lchown_windows(self):
1943-
p = self.cls(BASE) / 'fileA'
1944-
1945-
new_uid = 503
1946-
new_gid = 503
1947-
with self.assertRaises(NotImplementedError):
1948-
p.lchown(uid=new_uid, gid=new_gid)
19491929

19501930
# On Windows, os.chmod does not follow symlinks (issue #15411)
19511931
@only_posix
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
Add :func:`pathlib.Path.chown` and :func:`pathlib.Path.lchown`
2-
to :class:`pathlib.Path`. Patch by Jaspar Stach.
1+
Add :func:`pathlib.Path.chown` to :class:`pathlib.Path`. Patch by Jaspar Stach.

0 commit comments

Comments
 (0)