[issue21041] pathlib.PurePath.parents rejects negative indexes

2021-10-08 Thread Josh Rosenberg
Josh Rosenberg added the comment: Negative indexing is broken for absolute paths, see #45414. -- nosy: +josh.r ___ Python tracker ___

[issue21041] pathlib.PurePath.parents rejects negative indexes

2020-11-23 Thread Paul Ganssle
Paul Ganssle added the comment: New changeset 79d2e62c008446fbbc6f264bb8a30e2d38b6ff58 by Yaroslav Pankovych in branch 'master': Added support for negative indexes to PurePath.parents (GH-21799) https://github.com/python/cpython/commit/79d2e62c008446fbbc6f264bb8a30e2d38b6ff58 --

[issue21041] pathlib.PurePath.parents rejects negative indexes

2020-11-23 Thread Yaroslav Pankovych
Yaroslav Pankovych added the comment: Agree with that, it currently supports this behavior. -- ___ Python tracker ___ ___

[issue21041] pathlib.PurePath.parents rejects negative indexes

2020-11-23 Thread Paul Ganssle
Paul Ganssle added the comment: I think you may have confused my thoughts as to why this might be considered ambiguous with an actual suggestion for what the semantics should be. I think that we should stick with `p.parents[x] == tuple(p.parents)[x]` for any valid value of `x`, which means

[issue21041] pathlib.PurePath.parents rejects negative indexes

2020-11-23 Thread Yaroslav Pankovych
Yaroslav Pankovych added the comment: And it looks like a special case, so "Special cases aren't special enough to break the rules." -- ___ Python tracker ___

[issue21041] pathlib.PurePath.parents rejects negative indexes

2020-11-21 Thread Yaroslav Pankovych
Yaroslav Pankovych added the comment: That makes sense, but should we have this behaviour only for negative indices? We'll end up with something lie: path.parents[len(path.parents) - 1] != path.parents[-1] I think that is should be consistent regardless of negative/positive indices.

[issue21041] pathlib.PurePath.parents rejects negative indexes

2020-11-19 Thread Paul Ganssle
Paul Ganssle added the comment: I am not seeing any compelling reasons to avoid supporting negative indexes *or* slices here. If I had to guess about the confusing semantics of negative indices, I would guess it's the fact that the index in the -1 position for a non-empty Path will always

[issue21041] pathlib.PurePath.parents rejects negative indexes

2020-08-22 Thread Yaroslav Pankovych
Yaroslav Pankovych added the comment: Any thoughts about that folks? It's a pretty old bug, let's decide smth for it. -- ___ Python tracker ___

[issue21041] pathlib.PurePath.parents rejects negative indexes

2020-08-10 Thread Yaroslav Pankovych
Yaroslav Pankovych added the comment: Here's possible fix: https://github.com/python/cpython/pull/21799 -- ___ Python tracker ___

[issue21041] pathlib.PurePath.parents rejects negative indexes

2020-08-10 Thread Yaroslav Pankovych
Yaroslav Pankovych added the comment: 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: >>>

[issue21041] pathlib.PurePath.parents rejects negative indexes

2020-07-08 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Maxwell, in your case a more correct and obvious way is Path('/tmp') in filepath.parents although it may be not very efficient. Using the is_relative_to() method may be more efficient and obvious. -- nosy: +serhiy.storchaka

[issue21041] pathlib.PurePath.parents rejects negative indexes

2020-07-07 Thread Maxwell Ballenger
Maxwell Ballenger 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

[issue21041] pathlib.PurePath.parents rejects negative indexes

2020-03-09 Thread Julin
Julin added the comment: Can't this be implemented? This is something that a user would expect. Intuitive. And it looks as if it is an easy change to make that doesn't disturb anything else. -- nosy: +ju-sh ___ Python tracker

[issue21041] pathlib.PurePath.parents rejects negative indexes

2020-03-04 Thread victorg
victorg added the comment: Allow negative indexes that could be usefull. Example: to compare 2 or more Path, if they come from the same top directory from pathlib import Path a = Path("/a/testpy/cpython/config.log") b = Path("/b/testpy/cpython/config.log") c =

[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

[issue21041] pathlib.PurePath.parents rejects negative indexes

2019-09-13 Thread Julien Palard
Julien Palard added the comment: I checked conversation in #7951, tells about an ambiguity because it could be an index from a sequence or a key for a dict, like {-1: "foo"}. Here there is no such confusion. Confusion *may* arrise from the fact that it's not composed of parts, but more

[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

[issue21041] pathlib.PurePath.parents rejects negative indexes

2018-12-16 Thread Mark Lawrence
Change by Mark Lawrence : -- nosy: -BreamoreBoy ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue21041] pathlib.PurePath.parents rejects negative indexes

2018-12-16 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- type: behavior -> enhancement versions: +Python 3.8 -Python 3.4, Python 3.5 ___ Python tracker ___

[issue21041] pathlib.PurePath.parents rejects negative indexes

2014-08-18 Thread Akira Li
Akira Li added the comment: #7951 has an interesting debate on negative indexes that is possibly applicable here. Mark could you point to a message that explains why p.parents[-2] is worse than p.parents[len(p.parents)-2]? -- ___ Python tracker

[issue21041] pathlib.PurePath.parents rejects negative indexes

2014-07-14 Thread Barry A. Warsaw
Changes by Barry A. Warsaw ba...@python.org: -- nosy: +barry ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21041 ___ ___ Python-bugs-list mailing

[issue21041] pathlib.PurePath.parents rejects negative indexes

2014-07-14 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: Aren't negative indexes well defined in Python? E.g. p = Path('/tmp/tmp123/foo/bar/baz.xz') p.parents[len(p.parents)-2] PosixPath('/tmp') p.parents[-2] should == p.parents[len(p.parents)-2] -- ___ Python

[issue21041] pathlib.PurePath.parents rejects negative indexes

2014-07-14 Thread akira
akira added the comment: Aren't negative indexes well defined in Python? yes. I've provided the link to Python docs [1] in msg214642 that explicitly defines the behavior: If i or j is negative, the index is relative to the end of the string: len(s) + i or len(s) + j is substituted. But

[issue21041] pathlib.PurePath.parents rejects negative indexes

2014-07-14 Thread Mark Lawrence
Mark Lawrence added the comment: #7951 has an interesting debate on negative indexes that is possibly applicable here. -- nosy: +BreamoreBoy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21041

[issue21041] pathlib.PurePath.parents rejects negative indexes

2014-04-08 Thread akira
akira added the comment: From https://docs.python.org/3/glossary.html#term-sequence An iterable which supports efficient element access using integer indices via the __getitem__() special method and defines a __len__() method that returns the length of the sequence. .parents *is* a

[issue21041] pathlib.PurePath.parents rejects negative indexes

2014-03-24 Thread akira
Changes by akira 4kir4...@gmail.com: -- type: - behavior ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21041 ___ ___ Python-bugs-list mailing

[issue21041] pathlib.PurePath.parents rejects negative indexes

2014-03-24 Thread R. David Murray
Changes by R. David Murray rdmur...@bitdance.com: -- nosy: +pitrou, r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21041 ___ ___

[issue21041] pathlib.PurePath.parents rejects negative indexes

2014-03-24 Thread R. David Murray
R. David Murray added the comment: I think this is a doc bug. That object shouldn't be called a sequence, since it isn't one. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21041 ___

[issue21041] pathlib.PurePath.parents rejects negative indexes

2014-03-24 Thread Antoine Pitrou
Antoine Pitrou added the comment: Well, it is a sequence, it's just that it doesn't respect the convention about negative indices :-) As to why they are disallowed, I don't remember exactly (!) but I think it's because the exact semantics would be confusing otherwise. --

[issue21041] pathlib.PurePath.parents rejects negative indexes

2014-03-24 Thread R. David Murray
R. David Murray added the comment: Which is exactly what I mean by saying it is not a sequence. It is 'sequence-like'. Kind of like email Messages are dict-like: they share many methods and behaviors, but the exact behaviors and semantics are different. --

[issue21041] pathlib.PurePath.parents rejects negative indexes

2014-03-23 Thread akira
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`