mirror of
https://github.com/python/cpython.git
synced 2025-08-27 20:25:18 +00:00
Added support for negative indexes to PurePath.parents (GH-21799)
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>
This commit is contained in:
parent
ffae93248a
commit
79d2e62c00
7 changed files with 15 additions and 5 deletions
|
@ -632,7 +632,8 @@ class _PathParents(Sequence):
|
|||
def __getitem__(self, idx):
|
||||
if isinstance(idx, slice):
|
||||
return tuple(self[i] for i in range(*idx.indices(len(self))))
|
||||
if idx < 0 or idx >= len(self):
|
||||
|
||||
if idx >= len(self) or idx < -len(self):
|
||||
raise IndexError(idx)
|
||||
return self._pathcls._from_parsed_parts(self._drv, self._root,
|
||||
self._parts[:-idx - 1])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue