Skip to content

Commit 421bf4e

Browse files
committed
gh-134639: Clarify what "canonical" means in os.path.realpath
Improve documentation for os.path.realpath by clearly defining what a "canonical path" means. The updated documentation now explicitly states that a canonical path: - Is an absolute path - Has all symbolic links resolved - Is normalized (redundant separators, '.' and '..' components removed) Also clarify platform-specific behavior: - On Windows: resolves MS-DOS (8.3) style names and junction points - On POSIX: roughly equivalent to the system's realpath() function Closes #134639
1 parent 3c05251 commit 421bf4e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Doc/library/os.path.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,18 @@ the :mod:`glob` module.)
403403

404404
.. function:: realpath(path, *, strict=False)
405405

406-
Return the canonical path of the specified filename, eliminating any symbolic
407-
links encountered in the path (if they are supported by the operating
408-
system). On Windows, this function will also resolve MS-DOS (also called 8.3)
409-
style names such as ``C:\\PROGRA~1`` to ``C:\\Program Files``.
406+
Return the canonical path of the specified filename. A canonical path:
407+
408+
* Is an absolute path (always starts from the root of the filesystem)
409+
* Has all symbolic links resolved (if supported by the operating system)
410+
* Is normalized (redundant separators, ``.`` and ``..`` components are removed)
411+
412+
On Windows, this function will also resolve MS-DOS (also called 8.3)
413+
style names such as ``C:\\PROGRA~1`` to ``C:\\Program Files`` and
414+
will resolve junction points.
415+
416+
On POSIX systems, this function is roughly equivalent to the system's
417+
``realpath()`` function.
410418

411419
If a path doesn't exist or a symlink loop is encountered, and *strict* is
412420
``True``, :exc:`OSError` is raised. If *strict* is ``False`` these errors

0 commit comments

Comments
 (0)