[issue40752] Implement PurePath.__len__

2020-05-24 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Path is not a string with bells and whistles. It was intentionally made not a string subclass because some string operations (including len()) just do not make sense for path or are ambiguous. I am closing this as it goes against the initial design of path

[issue40752] Implement PurePath.__len__

2020-05-24 Thread Ram Rachum
Ram Rachum added the comment: I understand your argument. I think it relies on your earlier statement: "The fact the the path is stored as a string is an implementation detail." This statement reminds me of the term "architecture astronaut". Pathlib builds a cool architecture over the concep

[issue40752] Implement PurePath.__len__

2020-05-24 Thread Rémi Lapeyre
Rémi Lapeyre added the comment: > Remi: Your use case is taken care of by `len(path.parts)`. Yes, and your use case is taken care of by `len(str(path))` which works as well. The reason in the PR is to simplify: sorted(paths, key=lambda path: len(str(path)), reverse=True) to sorted(paths, k

[issue40752] Implement PurePath.__len__

2020-05-24 Thread Ram Rachum
Ram Rachum added the comment: Remi: Your use case is taken care of by `len(path.parts)`. Serhiy: "If it is not iterable, the length does not make sense." I'm not sure this is a rule. I do see that the `collections.abc.Sized` class does not require an `__iter__` method to be defined. ---

[issue40752] Implement PurePath.__len__

2020-05-24 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: If it is not iterable, the length does not make sense. Do you expect also len(-123) == 4? -- ___ Python tracker ___ __

[issue40752] Implement PurePath.__len__

2020-05-24 Thread Rémi Lapeyre
Rémi Lapeyre added the comment: PurePath is not iterable but I would expect len(Path('/home/remi/src/cpython')) == 4 The fact the the path is stored as a string is an implementation detail, it seems leaky to get the length of the string here. -- nosy: +remi.lapeyre ___

[issue40752] Implement PurePath.__len__

2020-05-24 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The length of the object is the number of some items in the object. It is usually tied with iteration: len(obj) == len(list(obj)). Is this true for PurePath? -- nosy: +serhiy.storchaka ___ Python tracker

[issue40752] Implement PurePath.__len__

2020-05-24 Thread Ram Rachum
Ram Rachum added the comment: Just return len(str(path)). I put the use case on the PR on GitHub. -- ___ Python tracker ___ ___ Pyt

[issue40752] Implement PurePath.__len__

2020-05-24 Thread Ram Rachum
Change by Ram Rachum : -- keywords: +patch pull_requests: +19611 stage: -> patch review pull_request: https://github.com/python/cpython/pull/20348 ___ Python tracker ___ _

[issue40752] Implement PurePath.__len__

2020-05-24 Thread SilentGhost
SilentGhost added the comment: What would it do? -- nosy: +SilentGhost, pitrou ___ Python tracker ___ ___ Python-bugs-list mailing

[issue40752] Implement PurePath.__len__

2020-05-24 Thread Ram Rachum
New submission from Ram Rachum : I'm writing the patch now. -- components: Library (Lib) messages: 369767 nosy: cool-RR priority: normal severity: normal status: open title: Implement PurePath.__len__ type: enhancement versions: Python 3.10 ___ Pytho