Skip to content

pathlib.Path.owner() and .group() should accept a follow_symlinks argument #103363

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
markrwilliams opened this issue Apr 8, 2023 · 5 comments
Closed
Labels
stdlib Python modules in the Lib dir topic-pathlib type-feature A feature request or enhancement

Comments

@markrwilliams
Copy link
Contributor

markrwilliams commented Apr 8, 2023

Feature or enhancement

pathlib.Path.owner() and pathlib.Path.group() always follow symbolic links. They should gain a new argument, follow_symlinks, that defaults to True. This will align their API with that of pathlib.Path.stat() and pathlib.Path.chmod()

Pitch

Most pathlib.Path methods follow symbolic links, so it's natural for these ownership methods to do the same.
However, doing so unconditionally results in a surprising error when you'd actually like them to look at a link's ownership - for example, to work with a system that uses dangling symbolic links as lock files - and there's no convenient API to call instead.

Previous discussion

#65521 brought up the same issue but proposed fixing it by changing the system call from stat to lstat, which was deemed too disruptive.
#18864 added follow_symlinks to pathlib.Path.stat and pathlib.Path.chmod. A commenter asked about adding this argument to other methods, namely is_file() and is_dir().

I'm happy to contribute the code if this seems worth doing.

Linked PRs

@markrwilliams markrwilliams added the type-feature A feature request or enhancement label Apr 8, 2023
@barneygale
Copy link
Contributor

Sounds reasonable to me!

@ganesh-k13
Copy link
Contributor

@markrwilliams are you working on this issue? I'd be happy to add it if you are not.

@kamilturek
Copy link
Contributor

Given no action for several months on this issue, I decided to open a PR.

@iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 23, 2023
kamilturek added a commit to kamilturek/cpython that referenced this issue Dec 2, 2023
@barneygale
Copy link
Contributor

Implemented by @kamilturek in #107962, merged into 3.13 as a1551b4 🎉

aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
@jb2170
Copy link
Contributor

jb2170 commented Jul 8, 2024

Nice

Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-pathlib type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

7 participants