Title: Parents objects in pathlib.Path don't support slices as __getitem__ arguments
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.8
Status: open Resolution:
Dependencies: 21041 Superseder:
Assigned To: Nosy List: brett.cannon, serhiy.storchaka, thejcannon
Priority: normal Keywords: patch

Created on 2018-12-14 16:55 by thejcannon, last changed 2018-12-17 21:52 by brett.cannon.

Pull Requests
URL Status Linked Edit
PR 11165 open thejcannon, 2018-12-14 19:13
Messages (3)
msg331841 - (view) Author: Joshua Cannon (thejcannon) * Date: 2018-12-14 16:55
I would expect the following to work:
>>> import pathlib
>>> pathlib.Path.cwd().parents[0:1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "...\Python36\lib\", line 593, in __getitem__
    if idx < 0 or idx >= len(self):
TypeError: '<' not supported between instances of 'slice' and 'int'

Since pathlib documents `parents` as a sequence-type, and slicing a sequence is pretty standard behavior.
msg331854 - (view) Author: Joshua Cannon (thejcannon) * Date: 2018-12-14 19:22
If it is deemed a bug which needs to be fixed, I've gone ahead and attached the PR to fix it.

CLA signage is pending approval at the company I work for, with most people out for the holidays (so it might be a day or two turnaround).
msg331923 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-12-16 11:27
See also issue21041. First than add support for slices, we should make a decision about negative indices.

In any case this is a new feature, which can be only added in the future 3.8 release.
Date User Action Args
2018-12-17 21:52:04brett.cannonsetnosy: + brett.cannon
2018-12-16 11:27:04serhiy.storchakasetversions: + Python 3.8, - Python 3.6
nosy: + serhiy.storchaka

messages: + msg331923

dependencies: + pathlib.PurePath.parents rejects negative indexes
2018-12-14 19:22:09thejcannonsetmessages: + msg331854
2018-12-14 19:13:25thejcannonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request10401
2018-12-14 16:55:17thejcannoncreate