[issue35498] Parents objects in pathlib.Path don't support slices as __getitem__ arguments

2019-09-13 Thread Joshua Cannon


Joshua Cannon  added the comment:

Pretty much the same reason you would want to slice any other sequence. You 
want some range of values.

top_most_3_dirs = myPath.parents[-3:]
grandparents_and_beyond = myPath.parents[1:]

The same goes for negative indexes.

--

___
Python tracker 
<https://bugs.python.org/issue35498>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21041] pathlib.PurePath.parents rejects negative indexes

2019-09-13 Thread Joshua Cannon


Joshua Cannon  added the comment:

> it may explain why negative indices or slices were initially not implemented: 
> It already looks like the result of a slice.

Sure the values of the sequence could be thought of as being increasingly 
smaller slices of some other sequence, however I don't think it changes the 
fact that "parents" is a sequence, and sequences have well-defined semantics 
for negative indices and slices. Semantics which people expect, and have to 
find smelly workarounds for.

--

___
Python tracker 
<https://bugs.python.org/issue21041>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21041] pathlib.PurePath.parents rejects negative indexes

2018-12-17 Thread Joshua Cannon


Joshua Cannon  added the comment:

I created issue35498 about .parents rejecting slices as well. (It was pointed 
out this discussion would probably decide that issue's fate)
I think that .parents looking like a duck, but not quacking like one isn't very 
pythonic.

Besides, the fact that p.parents[len(p.parents)-2] is allowed but p.parents[-2] 
is not just seems like extra steps. There's also list(p.parents)[-2], which is 
still not ideal. In either case, I'd imagine authors to put a comment like 
"PathLib .parents doesn't support negative indexes", which goes to show clients 
are expecting negative indices to work.

I see that this issue is several years old. I'm happy to shepherd it if it 
needs further contributions.

--
nosy: +thejcannon

___
Python tracker 
<https://bugs.python.org/issue21041>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35498] Parents objects in pathlib.Path don't support slices as __getitem__ arguments

2018-12-14 Thread Joshua Cannon


Joshua Cannon  added the comment:

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).

--

___
Python tracker 
<https://bugs.python.org/issue35498>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35498] Parents objects in pathlib.Path don't support slices as __getitem__ arguments

2018-12-14 Thread Joshua Cannon


Change by Joshua Cannon :


--
keywords: +patch
pull_requests: +10401
stage:  -> patch review

___
Python tracker 
<https://bugs.python.org/issue35498>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35498] Parents objects in pathlib.Path don't support slices as __getitem__ arguments

2018-12-14 Thread Joshua Cannon


New submission from Joshua Cannon :

I would expect the following to work:
```
>>> import pathlib
>>> pathlib.Path.cwd().parents[0:1]
Traceback (most recent call last):
  File "", line 1, in 
  File "...\Python36\lib\pathlib.py", 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.

--
components: Library (Lib)
messages: 331841
nosy: thejcannon
priority: normal
severity: normal
status: open
title: Parents objects in pathlib.Path don't support slices as __getitem__ 
arguments
type: enhancement
versions: Python 3.6

___
Python tracker 
<https://bugs.python.org/issue35498>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com