bpo-21041: Add negative indexing to pathlib path parents#21799
Conversation
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
|
Minor: The title says "negative slicing", however what this change is fixing is negative indexing. |
Thanks, fixed |
|
Hi @ypankovych, thanks for writing this PR. It's not sure this change will be accepted but it will require a NEWS entry, you can add one by using https://blurb-it.herokuapp.com/ |
|
@remilapeyre thanks, done. |
remilapeyre
left a comment
There was a problem hiding this comment.
Whether or not this is the wanted behaviour still needs to be discussed on the bpo issue, but the implementation looks correct to me. Thanks @ypankovych !
Misc/NEWS.d/next/Library/2020-08-10-15-06-55.bpo-21041.cYz1eL.rst
Outdated
Show resolved
Hide resolved
|
@remilapeyre thanks for your review. |
pganssle
left a comment
There was a problem hiding this comment.
@ypankovych Since we're changing the semantics of this, could you please add a .. versionchanged:: 3.10 annotation to the pathlib documentation, and add a "What's New" entry for Python 3.10?
Other than that, this looks good to me. Given the lack of explicit objections (Chesterton's fence aside) and the fact that this has been stalled on no one taking decisive action for the past 6 years or so, I'm inclined to go ahead and merge this once it has a What's New entry.
@pitrou As the original author of pathlib, do you have any objections to that course of action?
Misc/NEWS.d/next/Library/2020-08-10-15-06-55.bpo-21041.cYz1eL.rst
Outdated
Show resolved
Hide resolved
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
I have no objection to this :-) I'm not sure why I didn't add support for negative indexing, but it's probably laziness. |
|
@ypankovych I have merged #11165, which introduced some merge conflicts with this PR. Can you re-base against the master branch and resolve the conflicts? You'll also want to modify the |
|
I have made the requested changes; please review again |
|
Thanks for making the requested changes! @pganssle: please review the changes made to this pull request. |
This commit also fixes up some of the overlapping documentation changed in bpo-35498, which added support for indexing with slices. Fixes bpo-21041. https://bugs.python.org/issue21041 Co-authored-by: Paul Ganssle <p.ganssle@gmail.com> Co-authored-by: Rémi Lapeyre <remi.lapeyre@henki.fr>
cfbf0f6 to
0138810
Compare
This commit also fixes up some of the overlapping documentation changed in bpo-35498, which added support for indexing with slices. Fixes bpo-21041. https://bugs.python.org/issue21041 Co-authored-by: Paul Ganssle <p.ganssle@gmail.com> Co-authored-by: Rémi Lapeyre <remi.lapeyre@henki.fr>
As I can see, pathlib path parents don't support negative indexing:
That's kinda weird for python. I mean, in regular list/etc if I need the last element, I'd normally do list[-1], but here to get the last parent, I need to actually know how many parents do I have.
So now, I can do something like this:
So that's how I can get the last parent. But is it pythonic? No.
So, I decided to fix this, and now we can do negative indexing:
https://bugs.python.org/issue21041