Skip to content

gh-134639: Clarify what "canonical" means in os.path.realpath #134755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Doc/library/os.path.rst
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,18 @@ the :mod:`glob` module.)

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

Return the canonical path of the specified filename, eliminating any symbolic
links encountered in the path (if they are supported by the operating
system). On Windows, this function will also resolve MS-DOS (also called 8.3)
style names such as ``C:\\PROGRA~1`` to ``C:\\Program Files``.
Return the canonical path of the specified filename. A canonical path:

* Is an absolute path (always starts from the root of the filesystem)
* Has all symbolic links resolved (if supported by the operating system)
* Is normalized (redundant separators, ``.`` and ``..`` components are removed)

On Windows, this function will also resolve MS-DOS (also called 8.3)
style names such as ``C:\\PROGRA~1`` to ``C:\\Program Files`` and
will resolve junction points.

On POSIX systems, this function is roughly equivalent to the system's
``realpath()`` function.

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