Skip to content

Conversation

@ashm-dev
Copy link
Contributor

@ashm-dev ashm-dev commented May 26, 2025

Summary

This PR improves the documentation for os.path.realpath by clearly defining what a "canonical path" means. The current documentation only mentions symlink resolution but doesn't explain other aspects of canonicalization.

Details

The updated documentation now explicitly states that 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 removed)

It also clarifies 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

Related Issues

Closes #134639
Related to #134639


📚 Documentation preview 📚: https://cpython-previews--134755.org.readthedocs.build/

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 python#134639
@calestyo
Copy link
Contributor

calestyo commented Aug 3, 2025

Thanks for the PR, but I think it should additionally specify whether or not the normalising includes folding consecutive / like in /foo//bar.

In particular it should be noted here, that in POSIX, two leading // are special. That is /tmp is the same as ///tmp, ////tmp etc., but not the same as //tmp - at least not per se (e.g. Linux however doesn't seem to treat a leading // specially.

@ashm-dev ashm-dev closed this Sep 8, 2025
@ashm-dev ashm-dev deleted the docs-os-path-realpath branch September 8, 2025 14:47
@calestyo
Copy link
Contributor

calestyo commented Sep 8, 2025

@ashm-dev Unfortunately it still doesn't specify whether normalising includes folding of / (see comment above, includnig the special case of an absolute path starting with exactly two /).

@calestyo
Copy link
Contributor

calestyo commented Sep 8, 2025

ah... ignore my last mail... blindly I've assumed the branch was merged, but it was closed ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

properly define what "canonical" means in os.path.realpath

2 participants