-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
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
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.
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
|
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]>
|
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 |
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?) |
This all sounds great to me.
Why would accessing |
Oh, I suppose you might want to |
(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 |
Following up on the forum: https://discuss.python.org/t/ergonomics-of-new-pathlib-path-scandir/71721/30 |
I've removed |
This comment was marked as spam.
This comment was marked as spam.
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
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 <[email protected]>
Change the default value of
PurePathBase.parser
fromParserBase()
toposixpath
. As a result, user subclasses ofPurePathBase
andPathBase
use POSIX path syntax by default, which is very often desirable.Move
pathlib._abc.ParserBase
topathlib._types.Parser
, and convert it to a runtime-checkable protocol.No user-facing changes as the pathlib ABCs are still private.