[issue21041] pathlib.PurePath.parents rejects negative indexes

Maxwell Ballenger report at bugs.python.org
Tue Jul 7 21:41:55 EDT 2020


Maxwell Ballenger <ballengerm at gmail.com> added the comment:

Use case: I want to see if a Path is a descendent of /tmp.

if filepath.parents[-2] == Path('tmp'):

turns into

if filepath.parents[len(filepath.parents)-2] == Path('tmp'):

----------
nosy: +maxballenger

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue21041>
_______________________________________


More information about the Python-bugs-list mailing list