diff options
| author | Yaroslav Pankovych <31005942+ypankovych@users.noreply.github.com> | 2020-11-23 22:06:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-23 15:06:22 -0500 |
| commit | 79d2e62c008446fbbc6f264bb8a30e2d38b6ff58 (patch) | |
| tree | 19897f3bf2d3abafff8fbcda7c51bcbb446265b6 /Lib/pathlib.py | |
| parent | ffae93248a33cd6fe73d1ea85d6802765bbf56d2 (diff) | |
| download | cpython-git-79d2e62c008446fbbc6f264bb8a30e2d38b6ff58.tar.gz | |
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>
Diffstat (limited to 'Lib/pathlib.py')
| -rw-r--r-- | Lib/pathlib.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py index af310393c3..531a699a40 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -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]) |
