-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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-43757: make pathlib use os.path.realpath() to resolve all symlinks in a path #25264
Conversation
46b35c6
to
2bb4dd4
Compare
Summary of the differences between Before this patch:
After this patch:
|
Note that |
b6ca430
to
984a6fc
Compare
Thanks. I've made this adjustment and also rebased to fix conflicts. |
Looks like the
This doesn't agree with my expectations, nor with the first sentence of the function documentation:
A symlink loop doesn't seem like a good reason to break the bolded guarantee. |
|
I have nothing useful to add. I think @serhiy-storchaka is the person to ask. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not declaring an opinion yet on the behaviour change, but I think it's probably okay. I'd be happier if the link cycle change was also tied to the strict argument. (My main concern is that virtually nobody will be testing for it, and it can become an issue based entirely on user's setup - nothing to do with the code that will fail.)
Misc/NEWS.d/next/Library/2021-04-08-22-11-27.bpo-25264.hEqA5d.rst
Outdated
Show resolved
Hide resolved
I can make the new symlink loop handling optional, but in order to use it from pathlib it would need to be an additional argument, as I'd argue that the new behaviour is justified because the current behaviour seems entirely non-useful. I can't find another example of a |
This is probably true, but I don't want to add an earlier (and less expected) failure without more warning. Raising a warning in this case but not an error would be fine for 3.10 and 3.11, and then we could confidently make it raise an error in 3.12. That gives devs a few years to realise that an error might be occurring here and handle it properly (or choose to suppress it explicitly). |
Sounds very reasonable, thanks! I'll revise this patch. |
Some options for how we could retain the current
Leaning towards option 3. Any thoughts, or options I've missed? |
OK, I've updated this such that there's no change in non-strict Before this PR:
After this PR:
(by "muddle on" I mean append the remaining path components and return) |
…s in a path Removes a pathlib-specific implementation of `realpath()` that's mostly copied from `ntpath` and `posixpath`.
… when a new `strict=True` keyword-only argument is passed.
8ee02f2
to
df04357
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with this now, just want to wait for one more approval before merging.
Going to interpret silence as approval. Good work! Thanks for this patch. |
Thanks very much for your help! |
Bug was fixed by pythonGH-25264 which, for other reasons, moved to a system independent resolve. Adds tests for verifying resolve() on cases other than for symlinks. New cases include relative and absolute paths with and without dotted (./..) paths. Also renames test helper function to avoid name overloading and adds new REL_PATH test constant.
Removes a pathlib-specific implementation of
realpath()
that's mostlycopied from
ntpath
andposixpath
.https://bugs.python.org/issue43757