Skip to content

Commit cbac8a3

Browse files
authored
GH-121462: pathlib docs: improve table of corresponding os/os.path functions (#121465)
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 45614ec commit cbac8a3

File tree

1 file changed

+51
-36
lines changed

1 file changed

+51
-36
lines changed

Doc/library/pathlib.rst

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,39 +1864,54 @@ Corresponding tools
18641864
Below is a table mapping various :mod:`os` functions to their corresponding
18651865
:class:`PurePath`/:class:`Path` equivalent.
18661866

1867-
==================================== ==============================
1868-
:mod:`os` and :mod:`os.path` :mod:`pathlib`
1869-
==================================== ==============================
1870-
:func:`os.path.abspath` :meth:`Path.absolute`
1871-
:func:`os.path.realpath` :meth:`Path.resolve`
1872-
:func:`os.chmod` :meth:`Path.chmod`
1873-
:func:`os.mkdir` :meth:`Path.mkdir`
1874-
:func:`os.makedirs` :meth:`Path.mkdir`
1875-
:func:`os.rename` :meth:`Path.rename`
1876-
:func:`os.replace` :meth:`Path.replace`
1877-
:func:`os.rmdir` :meth:`Path.rmdir`
1878-
:func:`os.remove`, :func:`os.unlink` :meth:`Path.unlink`
1879-
:func:`os.getcwd` :func:`Path.cwd`
1880-
:func:`os.path.exists` :meth:`Path.exists`
1881-
:func:`os.path.expanduser` :meth:`Path.expanduser` and
1882-
:meth:`Path.home`
1883-
:func:`os.listdir` :meth:`Path.iterdir`
1884-
:func:`os.walk` :meth:`Path.walk`
1885-
:func:`os.path.isdir` :meth:`Path.is_dir`
1886-
:func:`os.path.isfile` :meth:`Path.is_file`
1887-
:func:`os.path.islink` :meth:`Path.is_symlink`
1888-
:func:`os.link` :meth:`Path.hardlink_to`
1889-
:func:`os.symlink` :meth:`Path.symlink_to`
1890-
:func:`os.readlink` :meth:`Path.readlink`
1891-
:func:`os.path.relpath` :meth:`PurePath.relative_to`
1892-
:func:`os.stat` :meth:`Path.stat`,
1893-
:meth:`Path.owner`,
1894-
:meth:`Path.group`
1895-
:func:`os.path.isabs` :meth:`PurePath.is_absolute`
1896-
:func:`os.path.join` :func:`PurePath.joinpath`
1897-
:func:`os.path.basename` :attr:`PurePath.name`
1898-
:func:`os.path.dirname` :attr:`PurePath.parent`
1899-
:func:`os.path.samefile` :meth:`Path.samefile`
1900-
:func:`os.path.splitext` :attr:`PurePath.stem` and
1901-
:attr:`PurePath.suffix`
1902-
==================================== ==============================
1867+
===================================== ==============================================
1868+
:mod:`os` and :mod:`os.path` :mod:`pathlib`
1869+
===================================== ==============================================
1870+
:func:`os.path.dirname` :attr:`PurePath.parent`
1871+
:func:`os.path.basename` :attr:`PurePath.name`
1872+
:func:`os.path.splitext` :attr:`PurePath.stem`, :attr:`PurePath.suffix`
1873+
:func:`os.path.join` :meth:`PurePath.joinpath`
1874+
:func:`os.path.isabs` :meth:`PurePath.is_absolute`
1875+
:func:`os.path.relpath` :meth:`PurePath.relative_to` [1]_
1876+
:func:`os.path.expanduser` :meth:`Path.expanduser` [2]_
1877+
:func:`os.path.realpath` :meth:`Path.resolve`
1878+
:func:`os.path.abspath` :meth:`Path.absolute` [3]_
1879+
:func:`os.path.exists` :meth:`Path.exists`
1880+
:func:`os.path.isfile` :meth:`Path.is_file`
1881+
:func:`os.path.isdir` :meth:`Path.is_dir`
1882+
:func:`os.path.islink` :meth:`Path.is_symlink`
1883+
:func:`os.path.isjunction` :meth:`Path.is_junction`
1884+
:func:`os.path.ismount` :meth:`Path.is_mount`
1885+
:func:`os.path.samefile` :meth:`Path.samefile`
1886+
:func:`os.getcwd` :meth:`Path.cwd`
1887+
:func:`os.stat` :meth:`Path.stat`
1888+
:func:`os.lstat` :meth:`Path.lstat`
1889+
:func:`os.listdir` :meth:`Path.iterdir`
1890+
:func:`os.walk` :meth:`Path.walk` [4]_
1891+
:func:`os.mkdir`, :func:`os.makedirs` :meth:`Path.mkdir`
1892+
:func:`os.link` :meth:`Path.hardlink_to`
1893+
:func:`os.symlink` :meth:`Path.symlink_to`
1894+
:func:`os.readlink` :meth:`Path.readlink`
1895+
:func:`os.rename` :meth:`Path.rename`
1896+
:func:`os.replace` :meth:`Path.replace`
1897+
:func:`os.remove`, :func:`os.unlink` :meth:`Path.unlink`
1898+
:func:`os.rmdir` :meth:`Path.rmdir`
1899+
:func:`os.chmod` :meth:`Path.chmod`
1900+
:func:`os.lchmod` :meth:`Path.lchmod`
1901+
===================================== ==============================================
1902+
1903+
.. rubric:: Footnotes
1904+
1905+
.. [1] :func:`os.path.relpath` calls :func:`~os.path.abspath` to make paths
1906+
absolute and remove "``..``" parts, whereas :meth:`PurePath.relative_to`
1907+
is a lexical operation that raises :exc:`ValueError` when its inputs'
1908+
anchors differ (e.g. if one path is absolute and the other relative.)
1909+
.. [2] :func:`os.path.expanduser` returns the path unchanged if the home
1910+
directory can't be resolved, whereas :meth:`Path.expanduser` raises
1911+
:exc:`RuntimeError`.
1912+
.. [3] :func:`os.path.abspath` removes "``..``" components without resolving
1913+
symlinks, which may change the meaning of the path, whereas
1914+
:meth:`Path.absolute` leaves any "``..``" components in the path.
1915+
.. [4] :func:`os.walk` always follows symlinks when categorizing paths into
1916+
*dirnames* and *filenames*, whereas :meth:`Path.walk` categorizes all
1917+
symlinks into *filenames* when *follow_symlinks* is false (the default.)

0 commit comments

Comments
 (0)