-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
the pathlib.Path.parents[-1]
didn't receive the self._parts
#93156
Comments
This looks like a bug in 79d2e62 - negative indices into |
barneygale
added a commit
to barneygale/cpython
that referenced
this issue
May 26, 2022
…h().parents` When a `_PathParents` object has a drive or a root, the length of the object is *one less* than than the length of `self._parts`, which resulted in an off-by-one error when `path.parents[-n]` was fed through to `self._parts[:-n - 1]`. In particular, `path.parents[-1]` was a malformed path object with spooky properties. This is addressed by adding `len(self)` to negative indices.
Seems to be a duplicate of #89577 (which doesn't have a PR) [Edit: after looking through the comments on that issue, @MojoVampire came up with the same fix.] |
brettcannon
pushed a commit
that referenced
this issue
Jun 3, 2022
…rents` (GH-93273) When a `_PathParents` object has a drive or a root, the length of the object is *one less* than than the length of `self._parts`, which resulted in an off-by-one error when `path.parents[-n]` was fed through to `self._parts[:-n - 1]`. In particular, `path.parents[-1]` was a malformed path object with spooky properties. This is addressed by adding `len(self)` to negative indices.
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Jun 3, 2022
…h().parents` (pythonGH-93273) When a `_PathParents` object has a drive or a root, the length of the object is *one less* than than the length of `self._parts`, which resulted in an off-by-one error when `path.parents[-n]` was fed through to `self._parts[:-n - 1]`. In particular, `path.parents[-1]` was a malformed path object with spooky properties. This is addressed by adding `len(self)` to negative indices. (cherry picked from commit f32e6b4) Co-authored-by: Barney Gale <barney.gale@gmail.com>
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Jun 3, 2022
…h().parents` (pythonGH-93273) When a `_PathParents` object has a drive or a root, the length of the object is *one less* than than the length of `self._parts`, which resulted in an off-by-one error when `path.parents[-n]` was fed through to `self._parts[:-n - 1]`. In particular, `path.parents[-1]` was a malformed path object with spooky properties. This is addressed by adding `len(self)` to negative indices. (cherry picked from commit f32e6b4) Co-authored-by: Barney Gale <barney.gale@gmail.com>
miss-islington
added a commit
that referenced
this issue
Jun 3, 2022
…rents` (GH-93273) When a `_PathParents` object has a drive or a root, the length of the object is *one less* than than the length of `self._parts`, which resulted in an off-by-one error when `path.parents[-n]` was fed through to `self._parts[:-n - 1]`. In particular, `path.parents[-1]` was a malformed path object with spooky properties. This is addressed by adding `len(self)` to negative indices. (cherry picked from commit f32e6b4) Co-authored-by: Barney Gale <barney.gale@gmail.com>
miss-islington
added a commit
that referenced
this issue
Jun 3, 2022
…rents` (GH-93273) When a `_PathParents` object has a drive or a root, the length of the object is *one less* than than the length of `self._parts`, which resulted in an off-by-one error when `path.parents[-n]` was fed through to `self._parts[:-n - 1]`. In particular, `path.parents[-1]` was a malformed path object with spooky properties. This is addressed by adding `len(self)` to negative indices. (cherry picked from commit f32e6b4) Co-authored-by: Barney Gale <barney.gale@gmail.com>
#93273 has been merged and backported. A |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
the
pathlib.Path.parents[-1]
didn't receive theself._parts
example:
source code in
pathlib.py
:when the idx is -1,
-idx - 1 = 0
. so theself._parts[: -idx -1 ]
is empty. hence then theparents[-1] != parents[2]
because the_parts
is different.Your environment
Manjaro Linux 21.2.6 Linux manjaro-5800 5.4.195-1-MANJARO #1 SMP PREEMPT Wed May 18 09:23:31 UTC 2022 x86_64 GNU/Linux
The text was updated successfully, but these errors were encountered: