Skip to content
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

bpo-41357: Add a sentence to os.path.abspath() clarifying that it pre… #21596

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

websurfer5
Copy link
Contributor

@websurfer5 websurfer5 commented Jul 23, 2020

…serves symlink names. Also, replace "os.path.abspath" with "os.path.realpath" in the table at the end of the Path class section.

https://bugs.python.org/issue41357

…serves symlink names. Also, replace "os.path.abspath" with "os.path.realpath" in the table at the end of the Path class section.
@@ -65,7 +65,8 @@ the :mod:`glob` module.)

Return a normalized absolutized version of the pathname *path*. On most
platforms, this is equivalent to calling the function :func:`normpath` as
follows: ``normpath(join(os.getcwd(), path))``.
follows: ``normpath(join(os.getcwd(), path))``. Unlike :func:`realpath`,
this function preserves symlink names.
Copy link
Contributor

@eryksun eryksun Jul 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be phrased in the negative that "this function does not resolve symlink targets".

If the reader follows through to the documentation of normpath, it's clear that it resolves ".." components, which may remove symlinks from the path. But based on just this sentence, it's not clear what it means to preserve symlinks. A different implementation might retain all ".." components, as pathlib's absolute method does. But the current implementation can change the real target of a Unix path, e.g. normpath('spam/symlink/../eggs') -> "spam/eggs".

In Windows, this is usually not a problem since the Windows API works like this anyway. The one exception is in the target of a relative symlink, e.g. symlink(r'spam\symlink\..\eggs', 'eggs') is not the same as symlink(r'spam\eggs', 'eggs').

Copy link
Contributor Author

@websurfer5 websurfer5 Jul 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the wording to more closely reflect, in a negative fashion, the language used for realpath().

eamanu
eamanu approved these changes Jul 24, 2020
Copy link
Contributor

@eamanu eamanu left a comment

I don't know if is necessary a NEWS here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review docs Documentation in the Doc dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants