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

Confusing wording in os.path.lexists docs #117360

Closed
pfortin opened this issue Mar 29, 2024 · 6 comments
Closed

Confusing wording in os.path.lexists docs #117360

pfortin opened this issue Mar 29, 2024 · 6 comments
Labels
docs Documentation in the Doc dir

Comments

@pfortin
Copy link

pfortin commented Mar 29, 2024

os.path.lexists(path) https://docs.python.org/3/library/os.path.html#os.path.lexists

Return True if path refers to an existing path. Returns **True** for broken symbolic links. Equivalent to [exists()](https://docs.python.org/3/library/os.path.html#os.path.exists) on platforms lacking [os.lstat()](https://docs.python.org/3/library/os.html#os.lstat).

Should read False

Linked PRs

@pfortin pfortin added the docs Documentation in the Doc dir label Mar 29, 2024
@eryksun
Copy link
Contributor

eryksun commented Mar 29, 2024

os.path.lexists() doesn't follow symlinks, so it returns True for a broken symlink. Use os.path.exists() if you need False for a broken symlink.

@pfortin
Copy link
Author

pfortin commented Mar 29, 2024

But what is the purpose of a function that only returns True?

@eryksun
Copy link
Contributor

eryksun commented Mar 29, 2024

os.path.lexists() returns True only if path exists, regardless of the file type. It's useful when one needs to know whether anything with the given name exists, regardless of whether it's a regular file, directory, symlink, named pipe/socket, or device.

@terryjreedy
Copy link
Member

If the doc matches the behavior, there is no bug. If the behavior is intended, and useful, we are unlikely to change it. Feature changes usually need be be discussed on discuss/ideas.

@terryjreedy terryjreedy closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2024
@zware
Copy link
Member

zware commented Mar 29, 2024

As already explained, there's no bug in the docs or implementation here. However, we might be able to clarify the docs a bit: I think the confusion here came from the fact that the broken symlink case is called out explicitly in a separate sentence:

Return ``True`` if *path* refers to an existing path. Returns ``True`` for
broken symbolic links. Equivalent to :func:`exists` on platforms lacking

This reads a bit clearer to me:

Return True if path refers to an existing path, including broken symbolic links.

@terryjreedy terryjreedy reopened this Mar 29, 2024
@zware zware changed the title True should read False Confusing wording in os.path.lexists docs Apr 2, 2024
erlend-aasland pushed a commit that referenced this issue Apr 9, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Apr 9, 2024
…117679)

(cherry picked from commit 73906d5)

Co-authored-by: Nice Zombies <[email protected]>
Co-authored-by: Zachary Ware <[email protected]>
@erlend-aasland
Copy link
Contributor

erlend-aasland pushed a commit that referenced this issue Apr 9, 2024
… (#117701)

(cherry picked from commit 73906d5)

Co-authored-by: Nice Zombies <[email protected]>
Co-authored-by: Zachary Ware <[email protected]>
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

5 participants