[issue45414] pathlib.Path.parents negative indexing is wrong for absolute paths

2021-10-08 Thread Josh Rosenberg
Josh Rosenberg added the comment: On the subject of sleep-deprived and/or sloppy, just realized: return self.__getitem__(len(self) + idx) should really just be: idx += len(self) no need to recurse. -- ___ Python tracker

[issue45414] pathlib.Path.parents negative indexing is wrong for absolute paths

2021-10-08 Thread Josh Rosenberg
Josh Rosenberg added the comment: "We'll definitely want to make sure that we're careful about bad indices ... since it would be easy to get weird behavior where too-large negative indexes start 'wrapping around'" When I noticed the problem, I originally thought "Hey, the test for a negative

[issue45414] pathlib.Path.parents negative indexing is wrong for absolute paths

2021-10-08 Thread Paul Ganssle
Paul Ganssle added the comment: This is a great bug report, but for anyone else who gets a bit lost in the details, here's the core of the issue: >>> p = Path("/1/2") >>> q = Path("1/2") >>> p.parents[-1] # This is correct PosixPath('/') >>> q.parents[-1] PosixPath('.') >>> p.parents[-2]

[issue45414] pathlib.Path.parents negative indexing is wrong for absolute paths

2021-10-08 Thread Paul Ganssle
Change by Paul Ganssle : -- nosy: +p-ganssle ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue45414] pathlib.Path.parents negative indexing is wrong for absolute paths

2021-10-08 Thread Josh Rosenberg
New submission from Josh Rosenberg : At least on PosixPath (not currently able to try on Windows to check WindowsPath, but from a quick code check I think it'll behave the same way), the negative indexing added in #21041 is implemented incorrectly for absolute paths. Passing either -1 or -2