Skip to content

Commit 6d1586d

Browse files
committed
[3.12] 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 7a874b4 commit 6d1586d

File tree

1 file changed

+40
-37
lines changed

1 file changed

+40
-37
lines changed

Doc/library/pathlib.rst

+40-37
Original file line numberDiff line numberDiff line change
@@ -1380,30 +1380,19 @@ Renaming and deleting
13801380
Remove this directory. The directory must be empty.
13811381

13821382

1383-
Other methods
1384-
^^^^^^^^^^^^^
1385-
1386-
.. classmethod:: Path.cwd()
1387-
1388-
Return a new path object representing the current directory (as returned
1389-
by :func:`os.getcwd`)::
1390-
1391-
>>> Path.cwd()
1392-
PosixPath('/home/antoine/pathlib')
1393-
1383+
Ownership and permissions
1384+
^^^^^^^^^^^^^^^^^^^^^^^^^
13941385

1395-
.. classmethod:: Path.home()
1386+
.. method:: Path.owner()
13961387

1397-
Return a new path object representing the user's home directory (as
1398-
returned by :func:`os.path.expanduser` with ``~`` construct). If the home
1399-
directory can't be resolved, :exc:`RuntimeError` is raised.
1388+
Return the name of the user owning the file. :exc:`KeyError` is raised
1389+
if the file's user identifier (UID) isn't found in the system database.
14001390

1401-
::
14021391

1403-
>>> Path.home()
1404-
PosixPath('/home/antoine')
1392+
.. method:: Path.group()
14051393

1406-
.. versionadded:: 3.5
1394+
Return the name of the group owning the file. :exc:`KeyError` is raised
1395+
if the file's group identifier (GID) isn't found in the system database.
14071396

14081397

14091398
.. method:: Path.chmod(mode, *, follow_symlinks=True)
@@ -1427,37 +1416,51 @@ Other methods
14271416
The *follow_symlinks* parameter was added.
14281417

14291418

1430-
.. method:: Path.expanduser()
1419+
.. method:: Path.lchmod(mode)
14311420

1432-
Return a new path with expanded ``~`` and ``~user`` constructs,
1433-
as returned by :meth:`os.path.expanduser`. If a home directory can't be
1434-
resolved, :exc:`RuntimeError` is raised.
1421+
Like :meth:`Path.chmod` but, if the path points to a symbolic link, the
1422+
symbolic link's mode is changed rather than its target's.
14351423

1436-
::
14371424

1438-
>>> p = PosixPath('~/films/Monty Python')
1439-
>>> p.expanduser()
1440-
PosixPath('/home/eric/films/Monty Python')
1425+
Other methods
1426+
^^^^^^^^^^^^^
14411427

1442-
.. versionadded:: 3.5
1428+
.. classmethod:: Path.cwd()
14431429

1430+
Return a new path object representing the current directory (as returned
1431+
by :func:`os.getcwd`)::
14441432

1445-
.. method:: Path.group()
1433+
>>> Path.cwd()
1434+
PosixPath('/home/antoine/pathlib')
14461435

1447-
Return the name of the group owning the file. :exc:`KeyError` is raised
1448-
if the file's gid isn't found in the system database.
14491436

1437+
.. classmethod:: Path.home()
14501438

1451-
.. method:: Path.lchmod(mode)
1439+
Return a new path object representing the user's home directory (as
1440+
returned by :func:`os.path.expanduser` with ``~`` construct). If the home
1441+
directory can't be resolved, :exc:`RuntimeError` is raised.
14521442

1453-
Like :meth:`Path.chmod` but, if the path points to a symbolic link, the
1454-
symbolic link's mode is changed rather than its target's.
1443+
::
1444+
1445+
>>> Path.home()
1446+
PosixPath('/home/antoine')
14551447

1448+
.. versionadded:: 3.5
14561449

1457-
.. method:: Path.owner()
14581450

1459-
Return the name of the user owning the file. :exc:`KeyError` is raised
1460-
if the file's uid isn't found in the system database.
1451+
.. method:: Path.expanduser()
1452+
1453+
Return a new path with expanded ``~`` and ``~user`` constructs,
1454+
as returned by :meth:`os.path.expanduser`. If a home directory can't be
1455+
resolved, :exc:`RuntimeError` is raised.
1456+
1457+
::
1458+
1459+
>>> p = PosixPath('~/films/Monty Python')
1460+
>>> p.expanduser()
1461+
PosixPath('/home/eric/films/Monty Python')
1462+
1463+
.. versionadded:: 3.5
14611464

14621465

14631466
.. method:: Path.readlink()

0 commit comments

Comments
 (0)