Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-20779 add chown() and lchown() to Path() in pathlib
No support for WindowsPath
  • Loading branch information
y0urself committed Feb 13, 2022
commit 89068025e43da426ec1c715d0a0d346df53e1192
19 changes: 19 additions & 0 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,19 @@ def lchmod(self, mode):
"""
self.chmod(mode, follow_symlinks=False)

def chown(self, uid, gid, *, dir_fd=None, follow_symlinks=True):
"""
Change the owner and group id of path to the numeric uid and gid, like os.chown().
"""
Comment on lines +1131 to +1133

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow PEP 8.

Suggested change
"""
Change the owner and group id of path to the numeric uid and gid, like os.chown().
"""
"""Change the owner and group id of path to the numeric uid and gid, like os.chown()."""

os.chown(self, uid, gid, dir_fd=dir_fd, follow_symlinks=follow_symlinks)

def lchown(self, uid, gid, *, dir_fd=None):
"""
Like chown(), except if the path points to a symlink, the symlink's
permissions are changed, rather than its target's.
"""
self.chown(uid, gid, dir_fd=dir_fd, follow_symlinks=False)

def unlink(self, missing_ok=False):
"""
Remove this file or link.
Expand Down Expand Up @@ -1393,3 +1406,9 @@ class WindowsPath(Path, PureWindowsPath):

def is_mount(self):
raise NotImplementedError("Path.is_mount() is unsupported on this system")

def chown(self, uid, gid, *, dir_fd=None, follow_symlinks=True):
raise NotImplementedError("Path.chown() is unsupported on this system")

def lchown(self, uid, gid, *, dir_fd=None):
raise NotImplementedError("Path.lchown() is unsupported on this system")