Skip to content

Commit 187cf8f

Browse files
committed
pythonGH-121462: pathlib docs: improve table of corresponding os/os.path functions
Re-order table of corresponding functions with the following priorities: 1. Pure functionality is at the top 2. `os.path` functions are shown before `os` functions 3. Similar functionality is kept together 4. Functionality follows docs order where possible Add a few missed correspondences: - `os.path.isjunction` and `Path.is_junction` - `os.path.ismount` and `Path.is_mount` - `os.lstat()` and `Path.lstat()` - `os.lchmod()` and `Path.lchmod()` Also add footnotes describing a few differences.
1 parent 53e1202 commit 187cf8f

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

Doc/library/pathlib.rst

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,36 +1831,49 @@ Below is a table mapping various :mod:`os` functions to their corresponding
18311831
==================================== ==============================
18321832
:mod:`os` and :mod:`os.path` :mod:`pathlib`
18331833
==================================== ==============================
1834-
:func:`os.path.abspath` :meth:`Path.absolute`
1834+
:func:`os.path.dirname` :attr:`PurePath.parent`
1835+
:func:`os.path.basename` :attr:`PurePath.name`
1836+
:func:`os.path.splitext` :attr:`PurePath.stem`, :attr:`PurePath.suffix`
1837+
:func:`os.path.join` :meth:`PurePath.joinpath`
1838+
:func:`os.path.isabs` :meth:`PurePath.is_absolute`
1839+
:func:`os.path.relpath` :meth:`PurePath.relative_to` [1]_
1840+
:func:`os.path.expanduser` :meth:`Path.expanduser` [2]_
18351841
:func:`os.path.realpath` :meth:`Path.resolve`
1836-
:func:`os.chmod` :meth:`Path.chmod`
1837-
:func:`os.mkdir` :meth:`Path.mkdir`
1838-
:func:`os.makedirs` :meth:`Path.mkdir`
1839-
:func:`os.rename` :meth:`Path.rename`
1840-
:func:`os.replace` :meth:`Path.replace`
1841-
:func:`os.rmdir` :meth:`Path.rmdir`
1842-
:func:`os.remove`, :func:`os.unlink` :meth:`Path.unlink`
1843-
:func:`os.getcwd` :func:`Path.cwd`
1842+
:func:`os.path.abspath` :meth:`Path.absolute` [3]_
18441843
:func:`os.path.exists` :meth:`Path.exists`
1845-
:func:`os.path.expanduser` :meth:`Path.expanduser` and
1846-
:meth:`Path.home`
1847-
:func:`os.listdir` :meth:`Path.iterdir`
1848-
:func:`os.walk` :meth:`Path.walk`
1849-
:func:`os.path.isdir` :meth:`Path.is_dir`
18501844
:func:`os.path.isfile` :meth:`Path.is_file`
1845+
:func:`os.path.isdir` :meth:`Path.is_dir`
18511846
:func:`os.path.islink` :meth:`Path.is_symlink`
1847+
:func:`os.path.isjunction` :meth:`Path.is_junction`
1848+
:func:`os.path.ismount` :meth:`Path.is_mount`
1849+
:func:`os.path.samefile` :meth:`Path.samefile`
1850+
:func:`os.getcwd` :meth:`Path.cwd`
1851+
:func:`os.stat` :meth:`Path.stat`
1852+
:func:`os.lstat` :meth:`Path.lstat`
1853+
:func:`os.listdir` :meth:`Path.iterdir`
1854+
:func:`os.walk` :meth:`Path.walk` [4]_
1855+
:func:`os.mkdir`, :func:`os.makedirs` :meth:`Path.mkdir`
18521856
:func:`os.link` :meth:`Path.hardlink_to`
18531857
:func:`os.symlink` :meth:`Path.symlink_to`
18541858
:func:`os.readlink` :meth:`Path.readlink`
1855-
:func:`os.path.relpath` :meth:`PurePath.relative_to`
1856-
:func:`os.stat` :meth:`Path.stat`,
1857-
:meth:`Path.owner`,
1858-
:meth:`Path.group`
1859-
:func:`os.path.isabs` :meth:`PurePath.is_absolute`
1860-
:func:`os.path.join` :func:`PurePath.joinpath`
1861-
:func:`os.path.basename` :attr:`PurePath.name`
1862-
:func:`os.path.dirname` :attr:`PurePath.parent`
1863-
:func:`os.path.samefile` :meth:`Path.samefile`
1864-
:func:`os.path.splitext` :attr:`PurePath.stem` and
1865-
:attr:`PurePath.suffix`
1859+
:func:`os.rename` :meth:`Path.rename`
1860+
:func:`os.replace` :meth:`Path.replace`
1861+
:func:`os.remove`, :func:`os.unlink` :meth:`Path.unlink`
1862+
:func:`os.rmdir` :meth:`Path.rmdir`
1863+
:func:`os.chmod` :meth:`Path.chmod`
1864+
:func:`os.lchmod` :meth:`Path.lchmod`
18661865
==================================== ==============================
1866+
1867+
.. [1] :func:`os.path.relpath` calls :func:`~os.path.abspath` to make paths
1868+
absolute and remove "``..``" parts, whereas :meth:`PurePath.relative_to`
1869+
is a lexical operation that raises :exc:`ValueError` when its inputs'
1870+
anchors differ (e.g. if one path is absolute and the other relative.)
1871+
.. [2] :func:`os.path.expanduser` returns the path unchanged if the home
1872+
directory can't be resolved, whereas :meth:`Path.expanduser` raises
1873+
:exc:`RuntimeError`.
1874+
.. [3] :func:`os.path.abspath` removes "``..``" components without resolving
1875+
symlinks, which may change the meaning of the path, whereas
1876+
:meth:`Path.absolute` leaves any "``..``" components in the path.
1877+
.. [4] :func:`os.walk` always follows symlinks when categorizing paths into
1878+
*dirnames* and *filenames*, whereas :meth:`Path.walk` categorizes all
1879+
symlinks into *filenames* when *follow_symlinks* is false (the default.)

0 commit comments

Comments
 (0)