[New-bugs-announce] [issue21041] pathlib.PurePath.parents rejects negative indexes

akira report at bugs.python.org
Sun Mar 23 23:16:51 CET 2014


New submission from akira:

`pathlib.PurePath.parents` is a sequence [1] but it rejects negative indexes:

  >>> from pathlib import PurePath
  >>> PurePath('a/b/c').parents[-2]
  Traceback (most recent call last):
  ...
  IndexError: -2

Sequences in Python interpret negative indexes as `len(seq) + i` [2]

I've included the patch that fixes the issue and adds corresponding tests. No documentation changes are needed.

[1]: http://docs.python.org/3/library/pathlib#pathlib.PurePath.parents
[2]: http://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range

----------
components: Library (Lib)
files: pathlib-parents-allow-negative-index.patch
keywords: patch
messages: 214642
nosy: akira
priority: normal
severity: normal
status: open
title: pathlib.PurePath.parents rejects negative indexes
versions: Python 3.4, Python 3.5
Added file: http://bugs.python.org/file34595/pathlib-parents-allow-negative-index.patch

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


More information about the New-bugs-announce mailing list