Skip to content

Commit af48eb9

Browse files
committed
[3.13] pythonGH-119054: Add "Permissions and ownership" section to pathlib docs. (pythonGH-120505)
Add dedicated subsection for `pathlib.owner()`, `group()`, `chmod()` and `lchmod()`. Co-authored-by: Hugo van Kemenade <[email protected]>. (cherry picked from commit e4a97a7) Co-authored-by: Barney Gale <[email protected]>
1 parent 0a77058 commit af48eb9

File tree

1 file changed

+51
-48
lines changed

1 file changed

+51
-48
lines changed

Doc/library/pathlib.rst

+51-48
Original file line numberDiff line numberDiff line change
@@ -1475,30 +1475,39 @@ Renaming and deleting
14751475
Remove this directory. The directory must be empty.
14761476

14771477

1478-
Other methods
1479-
^^^^^^^^^^^^^
1478+
Permissions and ownership
1479+
^^^^^^^^^^^^^^^^^^^^^^^^^
14801480

1481-
.. classmethod:: Path.cwd()
1481+
.. method:: Path.owner(*, follow_symlinks=True)
14821482

1483-
Return a new path object representing the current directory (as returned
1484-
by :func:`os.getcwd`)::
1483+
Return the name of the user owning the file. :exc:`KeyError` is raised
1484+
if the file's user identifier (UID) isn't found in the system database.
14851485

1486-
>>> Path.cwd()
1487-
PosixPath('/home/antoine/pathlib')
1486+
This method normally follows symlinks; to get the owner of the symlink, add
1487+
the argument ``follow_symlinks=False``.
14881488

1489+
.. versionchanged:: 3.13
1490+
Raises :exc:`UnsupportedOperation` if the :mod:`pwd` module is not
1491+
available. In earlier versions, :exc:`NotImplementedError` was raised.
14891492

1490-
.. classmethod:: Path.home()
1493+
.. versionchanged:: 3.13
1494+
The *follow_symlinks* parameter was added.
14911495

1492-
Return a new path object representing the user's home directory (as
1493-
returned by :func:`os.path.expanduser` with ``~`` construct). If the home
1494-
directory can't be resolved, :exc:`RuntimeError` is raised.
14951496

1496-
::
1497+
.. method:: Path.group(*, follow_symlinks=True)
14971498

1498-
>>> Path.home()
1499-
PosixPath('/home/antoine')
1499+
Return the name of the group owning the file. :exc:`KeyError` is raised
1500+
if the file's group identifier (GID) isn't found in the system database.
15001501

1501-
.. versionadded:: 3.5
1502+
This method normally follows symlinks; to get the group of the symlink, add
1503+
the argument ``follow_symlinks=False``.
1504+
1505+
.. versionchanged:: 3.13
1506+
Raises :exc:`UnsupportedOperation` if the :mod:`grp` module is not
1507+
available. In earlier versions, :exc:`NotImplementedError` was raised.
1508+
1509+
.. versionchanged:: 3.13
1510+
The *follow_symlinks* parameter was added.
15021511

15031512

15041513
.. method:: Path.chmod(mode, *, follow_symlinks=True)
@@ -1522,57 +1531,51 @@ Other methods
15221531
The *follow_symlinks* parameter was added.
15231532

15241533

1525-
.. method:: Path.expanduser()
1526-
1527-
Return a new path with expanded ``~`` and ``~user`` constructs,
1528-
as returned by :meth:`os.path.expanduser`. If a home directory can't be
1529-
resolved, :exc:`RuntimeError` is raised.
1534+
.. method:: Path.lchmod(mode)
15301535

1531-
::
1536+
Like :meth:`Path.chmod` but, if the path points to a symbolic link, the
1537+
symbolic link's mode is changed rather than its target's.
15321538

1533-
>>> p = PosixPath('~/films/Monty Python')
1534-
>>> p.expanduser()
1535-
PosixPath('/home/eric/films/Monty Python')
15361539

1537-
.. versionadded:: 3.5
1540+
Other methods
1541+
^^^^^^^^^^^^^
15381542

1543+
.. classmethod:: Path.cwd()
15391544

1540-
.. method:: Path.group(*, follow_symlinks=True)
1545+
Return a new path object representing the current directory (as returned
1546+
by :func:`os.getcwd`)::
15411547

1542-
Return the name of the group owning the file. :exc:`KeyError` is raised
1543-
if the file's gid isn't found in the system database.
1548+
>>> Path.cwd()
1549+
PosixPath('/home/antoine/pathlib')
15441550

1545-
This method normally follows symlinks; to get the group of the symlink, add
1546-
the argument ``follow_symlinks=False``.
15471551

1548-
.. versionchanged:: 3.13
1549-
Raises :exc:`UnsupportedOperation` if the :mod:`grp` module is not
1550-
available. In previous versions, :exc:`NotImplementedError` was raised.
1552+
.. classmethod:: Path.home()
15511553

1552-
.. versionchanged:: 3.13
1553-
The *follow_symlinks* parameter was added.
1554+
Return a new path object representing the user's home directory (as
1555+
returned by :func:`os.path.expanduser` with ``~`` construct). If the home
1556+
directory can't be resolved, :exc:`RuntimeError` is raised.
15541557

1558+
::
15551559

1556-
.. method:: Path.lchmod(mode)
1560+
>>> Path.home()
1561+
PosixPath('/home/antoine')
15571562

1558-
Like :meth:`Path.chmod` but, if the path points to a symbolic link, the
1559-
symbolic link's mode is changed rather than its target's.
1563+
.. versionadded:: 3.5
15601564

15611565

1562-
.. method:: Path.owner(*, follow_symlinks=True)
1566+
.. method:: Path.expanduser()
15631567

1564-
Return the name of the user owning the file. :exc:`KeyError` is raised
1565-
if the file's uid isn't found in the system database.
1568+
Return a new path with expanded ``~`` and ``~user`` constructs,
1569+
as returned by :meth:`os.path.expanduser`. If a home directory can't be
1570+
resolved, :exc:`RuntimeError` is raised.
15661571

1567-
This method normally follows symlinks; to get the owner of the symlink, add
1568-
the argument ``follow_symlinks=False``.
1572+
::
15691573

1570-
.. versionchanged:: 3.13
1571-
Raises :exc:`UnsupportedOperation` if the :mod:`pwd` module is not
1572-
available. In previous versions, :exc:`NotImplementedError` was raised.
1574+
>>> p = PosixPath('~/films/Monty Python')
1575+
>>> p.expanduser()
1576+
PosixPath('/home/eric/films/Monty Python')
15731577

1574-
.. versionchanged:: 3.13
1575-
The *follow_symlinks* parameter was added.
1578+
.. versionadded:: 3.5
15761579

15771580

15781581
.. method:: Path.readlink()

0 commit comments

Comments
 (0)