Skip to content

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

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

Closed
wants to merge 2 commits into from

Conversation

nphilipp
Copy link

@nphilipp nphilipp commented Jun 25, 2020

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
Contributor

This looks fine to me (note: I'm just some guy, not a core dev)

I'd argue that we're adding two ways to do the same thing (exists(follow_symlinks=False) and lexists()), where the former is more explicit, and so the addition of lexists() is unnecessary.

@nphilipp
Copy link
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
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
Contributor

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

@nphilipp
Copy link
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
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
Member

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 :)

Ah, I misinterpreted your "This looks fine to me" earlier comment :)

In that case, let's close this. There seems to have been little interest in the issue or the PR in the four-and-a-half years since the issue was opened, and the bar for additions to the stdlib is (quite rightly) high.

Thanks for the PR @nphilipp -- I hope this doesn't discourage you from contributing to CPython in the future!

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