Skip to content

Commit d4070a3

Browse files
committed
Add documentation for chown and lchown, fix typo in lchmod
1 parent dbdbbbe commit d4070a3

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

Doc/library/pathlib.rst

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,30 @@ 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)
759+
760+
Change the file ownership, like :func:`os.chown`.
761+
762+
This method normally follows symlinks. Some Unix flavours support changing
763+
permissions on the symlink itself; on these platforms you may add the
764+
argument ``follow_symlinks=False``, or use :meth:`~Path.lchown`.
765+
766+
::
767+
768+
>>> p = Path('setup.py')
769+
>>> p.stat().st_uid
770+
1000
771+
>>> p.stat().st_gid
772+
1000
773+
>>> p.chown(1, 20)
774+
>>> p.stat().st_uid
775+
1
776+
>>> p.stat().st_gid
777+
20
778+
779+
.. availability:: Unix.
780+
781+
758782
.. method:: Path.exists()
759783

760784
Whether the path points to an existing file or directory::
@@ -923,9 +947,17 @@ call fails (for example because the path doesn't exist).
923947
symbolic link's mode is changed rather than its target's.
924948

925949

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+
926958
.. method:: Path.lstat()
927959

928-
Like :meth:`Path.stat` but, if the path points to a symbolic link, return
960+
Like :meth:`Path.stat`, but if the path points to a symbolic link, return
929961
the symbolic link's information rather than its target's.
930962

931963

@@ -1260,6 +1292,7 @@ Below is a table mapping various :mod:`os` functions to their corresponding
12601292
:func:`os.path.abspath` :meth:`Path.absolute` [#]_
12611293
:func:`os.path.realpath` :meth:`Path.resolve`
12621294
:func:`os.chmod` :meth:`Path.chmod`
1295+
:func:`os.chown` :meth:`Path.chown`
12631296
:func:`os.mkdir` :meth:`Path.mkdir`
12641297
:func:`os.makedirs` :meth:`Path.mkdir`
12651298
:func:`os.rename` :meth:`Path.rename`

0 commit comments

Comments
 (0)