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
Parents objects in pathlib.Path don't support slices as __getitem__ arguments #79679
Comments
I would expect the following to work:
Since pathlib documents |
If it is deemed a bug which needs to be fixed, I've gone ahead and attached the PR to fix it. CLA signage is pending approval at the company I work for, with most people out for the holidays (so it might be a day or two turnaround). |
See also bpo-21041. First than add support for slices, we should make a decision about negative indices. In any case this is a new feature, which can be only added in the future 3.8 release. |
Just commented on the related issue: https://bugs.python.org/issue21041#msg352281 My question is: Why would you need to slice parents? parents already looks like the result of some slice. |
Pretty much the same reason you would want to slice any other sequence. You want some range of values. top_most_3_dirs = myPath.parents[-3:]
grandparents_and_beyond = myPath.parents[1:] The same goes for negative indexes. |
One question I would have about this is that The PR returns a list, but I'm inclined to say we should return a tuple. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: