Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
GH-127456: pathlib ABCs: add protocol for path parser#127494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
barneygale commented Dec 1, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
`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.
barneygale commented Dec 3, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
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 <[email protected]>
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 |
barneygale commented Dec 5, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reduced PR to just the parser changes LGTM
barneygale commented Dec 9, 2024
Thanks both, very much appreciate the feedback :-) |
5c89adf into python:mainUh oh!
There was an error while loading. Please reload this page.
…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 <[email protected]>
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.