gh-78318: Add pathlib.Path.lexists and related by nphilipp · Pull Request #21157 · python/cpython · GitHub
Skip to content

gh-78318: Add pathlib.Path.lexists and related - #21157

Closed
nphilipp wants to merge 2 commits into
python:mainfrom
nphilipp:master--pathlib-path-lexists
Closed

nphilipp wants to merge 2 commits into
python:mainfrom
nphilipp:master--pathlib-path-lexists

Conversation

@nphilipp

@nphilipp nphilipp commented Jun 25, 2020

Copy link
Copy Markdown

This adds the follow_symlink parameter to pathlib.Path.exists(),
and wraps the new functionality in pathlib.Path.lexists(), analogous
to os.stat() ./. os.lstat() and os.path.exists() ./.
os.path.lexists().

Signed-off-by: Nils Philippsen nils@tiptoe.de

@barneygale

Copy link
Copy Markdown
Contributor

@nphilipp

Copy link
Copy Markdown
Author

@barneygale You're right that .lexists() just wraps .exists(follow_symlinks=True). I put it in to have the same symmetry as with .chmod()/.lchmod() and .stat()/.lstat(). If we'd rather have both methods without parameters, I guess the implementation could be moved to a protected method and .exists() become a wrapper like .lexists() but if it's all the same I'd leave it as it is.

@nphilipp

Copy link
Copy Markdown
Author

Resolving conflicts.

@nphilipp
nphilipp force-pushed the master--pathlib-path-lexists branch from 0cf7578 to f4f3805 Compare January 22, 2021 08:49
@barneygale

Copy link
Copy Markdown
Contributor

The difference is that lchmod and lstat are bona fide system calls, whereas lexists isn't.

@nphilipp

Copy link
Copy Markdown
Author

I think you mean that they are standard library calls, neither have been syscalls in a long while (at least on Linux). My motivation, however, wasn't to make people coming from a POSIX-compliant C library "feel at home", but old fogies like me who're used to the os.path API. Anyway, some tests are failing, so there's work for me to do.

This adds the `follow_symlink` parameter to `pathlib.Path.exists()`,
and wraps the new functionality in `pathlib.Path.lexists()`, analogous
to `os.stat()` ./. `os.lstat()` and `os.path.exists()` ./.
`os.path.lexists()`.

GH-NNNN

Signed-off-by: Nils Philippsen <nils@tiptoe.de>
@AlexWaygood AlexWaygood changed the title bpo-34137: Add pathlib.Path.lexists and related gh-78318: Add pathlib.Path.lexists and related Jan 8, 2023
@barneygale

Copy link
Copy Markdown
Contributor

I'm still -1 on this, per Zen of Python's "There should be one -- and preferably only one -- obvious way to do it."

I'd rather we didn't have lstat() or lchmod() either, for the record :)

@AlexWaygood

Copy link
Copy Markdown
Member

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants