Uh oh!
There was an error while loading. Please reload this page.
GH-127456: pathlib ABCs: add protocol for path parser - #127494
Conversation
`posixpath`. As a result, user subclasses of `PurePathBase` and `PathBase` use POSIX path syntax by default, which is very often desirable.
…t it to a runtime-checkable protocol.
…ies. Objects of this type provide a subset of the `os.DirEntry` API, specifically those methods and attributes needed to implement `glob()` and `walk()`.
Objects of this type provide a small subset of the `os.stat_result` API, specifically attributes for the file type, permissions and location/offset.
Uh oh!
There was an error while loading. Please reload this page.
encukou
commented
Dec 3, 2024
This looks reasonable, but
Also, I guess typing has no way to say that e.g. if It seems that for your goal of supporting virtual filesystems, it might be better to rely on |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Thank you for the feedback and reviews.
I've occasionally thought about adding a I don't think |
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
encukou
commented
Dec 4, 2024
|
zooba
commented
Dec 4, 2024
I'm not a fan of the I'm not sure what such an API should look like, apart from I want it to have the |
encukou
commented
Dec 5, 2024
Brainstorming: A downside is that this breaks the rule that touching the filesystem is done by methods, not attributes. (Can we say rule was for getting “fresh” information, and we can use something else here?) |
barneygale
commented
Dec 5, 2024
This all sounds great to me.
Why would accessing |
Oh, I suppose you might want to |
barneygale
commented
Dec 5, 2024
zooba
commented
Dec 5, 2024
(Process note - we should probably move the API design discussion off this PR)
What we need to design is the way for a user to discover that they've got cached values, and reset it. A |
barneygale
commented
Dec 6, 2024
Following up on the forum: https://discuss.python.org/t/ergonomics-of-new-pathlib-path-scandir/71721/30 |
barneygale
commented
Dec 7, 2024
I've removed |
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
zooba
left a comment
There was a problem hiding this comment.
The reduced PR to just the parser changes LGTM
barneygale
commented
Dec 9, 2024
Thanks both, very much appreciate the feedback :-) |
…27494) Change the default value of `PurePathBase.parser` from `ParserBase()` to `posixpath`. As a result, user subclasses of `PurePathBase` and `PathBase` use POSIX path syntax by default, which is very often desirable. Move `pathlib._abc.ParserBase` to `pathlib._types.Parser`, and convert it to a runtime-checkable protocol. Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Change the default value of
PurePathBase.parserfromParserBase()toposixpath. As a result, user subclasses ofPurePathBaseandPathBaseuse POSIX path syntax by default, which is very often desirable.Move
pathlib._abc.ParserBasetopathlib._types.Parser, and convert it to a runtime-checkable protocol.No user-facing changes as the pathlib ABCs are still private.