[issue41511] Pathlib parents doesn't support slicing with negative indexes

2020-08-09 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Closing it as duplicate of issue21041. Thanks Remi. Yaroslav, feel free to 
discuss it in the other issue.

--
nosy: +xtreak
resolution:  -> duplicate
stage: patch review -> resolved
status: open -> closed
superseder:  -> pathlib.PurePath.parents rejects negative indexes

___
Python tracker 

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



[issue41511] Pathlib parents doesn't support slicing with negative indexes

2020-08-09 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

*This is a duplicate of issue 21041

--

___
Python tracker 

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



[issue41511] Pathlib parents doesn't support slicing with negative indexes

2020-08-09 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

This is a duplicate of 21041, it would be better to change the title of your PR 
so that it points to this bug report and to continue the discussion there.

--
nosy: +remi.lapeyre
versions:  -Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

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



[issue41511] Pathlib parents doesn't support slicing with negative indexes

2020-08-09 Thread Yaroslav


Yaroslav  added the comment:

Here's opened PR: https://github.com/python/cpython/pull/21799

--

___
Python tracker 

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



[issue41511] Pathlib parents doesn't support slicing with negative indexes

2020-08-09 Thread Roundup Robot


Change by Roundup Robot :


--
keywords: +patch
nosy: +python-dev
nosy_count: 1.0 -> 2.0
pull_requests: +20934
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21799

___
Python tracker 

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



[issue41511] Pathlib parents doesn't support slicing with negative indexes

2020-08-09 Thread Yaroslav


New submission from Yaroslav :

As I can see, pathlib path parents don't support slicing with negative indexes: 

>>> import pathlib
>>> path = pathlib.PosixPath("some/very/long/path/here")
>>> path.parents[-1]
...
raise IndexError(idx)
IndexError: -1

That's kinda weird for python. I mean, in regular list/etc if I need the last 
element, I'd normally do list[-1], but here to get the last parent, I need to 
actually know how many parents do I have. 

So now, I can do something like this:

>>> parents_count = len(path.parents) - 1
>>> path.parents[parents_count]
PosixPath('.')

So that's how I can get the last parent. But is it pythonic? No.

So, I decided to fix this, and now we can do negative slicing:

>>> path.parents[-1] == path.parents[parents_count]
True
>>> path.parents[-2] == path.parents[parents_count - 1]
True

So what do you guys think about this?

--
components: Library (Lib)
messages: 375076
nosy: ypank
priority: normal
severity: normal
status: open
title: Pathlib parents doesn't support slicing with negative indexes
type: behavior
versions: Python 3.10, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

___
Python tracker 

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