GeezerVison is showing github.com — GH-110109: Add `pathlib._PurePathBase` by barneygale · Pull Request #110670 · python/cpython
Conversation
barneygale
commented
Oct 11, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Add private pathlib._PurePathBase class: a private superclass of both PurePath and _PathBase. Unlike PurePath, it does not define any of these special methods: __fspath__, __bytes__, __reduce__, __hash__, __eq__, __lt__, __le__, __gt__, __ge__. Its initializer and path joining methods accept only strings, not os.PathLike objects more broadly.
This is important for supporting virtual paths: user subclasses of _PathBase that provide access to archive files, FTP servers, etc. In these classes, the above methods should be implemented by users only as appropriate, with due consideration for the hash/equality of any backing objects, such as file objects or sockets.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
edgarrmondragon reacted with thumbs up emoji
Add private `pathlib._PurePathBase` class: a private superclass of both
`PurePath` and `_PathBase`. Unlike `PurePath`, it does not define any of
these special methods: `__fspath__`, `__bytes__`, `__reduce__`, `__hash__`,
`__eq__`, `__lt__`, `__le__`, `__gt__`, `__ge__`.
This is important for supporting *virtual paths*: user subclasses of
`_PathBase` that provide access to archive files, FTP servers, etc. In
these classes, the above methods should be implemented by users only as
appropriate, with due consideration for the hash/equality of any backing
objects, such as file objects or sockets.
|
FYI @AlexWaygood. We avoided adding this class previously with your clever suggestion to set __fspath__ and __bytes__ to None in PathBase, and then restore their values in Path. (see #106082, #106337).
But I'm increasingly convinced that this extra class is needed after all - there are too many PurePath magic methods which shouldn't be inherited by PathBase. Hence this PR adds a new superclass.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
An inheritance diagram:

|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
barneygale
commented
Nov 13, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Quite a lot of this patch is re-ordering methods. I've split that stuff off into a preparatory PR, which will help make this PR easier to review:
#112012
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Once this lands, I plan to:
- Move
_PurePathBase and _PathBase into a new pathlib._abc module (likewise their tests)
- Copy-paste that code into a
pathlib_abc PyPI package, dropping the class underscore prefixes
- Engage with the community and iterate on
pathlib_abc (regularly syncing changes back to CPython) for at least a few months, more likely a couple years
- Drop the class underscore prefixes in CPython; make
pathlib_abc a backport-only package.
It's going to be a while before PurePathBase sees official public release in CPython, so I reckon we don't need to get its interface perfect in this PR. Hopefully that makes it less intimidating to review.
|
ktdreyer reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Given that this change is blocking work on pathlib ABCs, and should have no observable effects on any public APIs, I'm going to merge it without waiting any longer for review.
If that doesn't seem right to anyone, please let me know and I can revert it. I'm never quite sure where to draw the line on these things.
|
AlexWaygood reacted with heart emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
aisk
pushed a commit
to aisk/cpython
that referenced
this pull request
Feb 11, 2024
Add private `pathlib._PurePathBase` class: a private superclass of both `PurePath` and `_PathBase`. Unlike `PurePath`, it does not define any of these special methods: `__fspath__`, `__bytes__`, `__reduce__`, `__hash__`, `__eq__`, `__lt__`, `__le__`, `__gt__`, `__ge__`. Its initializer and path joining methods accept only strings, not os.PathLike objects more broadly.
This is important for supporting *virtual paths*: user subclasses of `_PathBase` that provide access to archive files, FTP servers, etc. In these classes, the above methods should be implemented by users only as appropriate, with due consideration for the hash/equality of any backing objects, such as file objects or sockets.
Glyphack
pushed a commit
to Glyphack/cpython
that referenced
this pull request
Sep 2, 2024
Add private `pathlib._PurePathBase` class: a private superclass of both `PurePath` and `_PathBase`. Unlike `PurePath`, it does not define any of these special methods: `__fspath__`, `__bytes__`, `__reduce__`, `__hash__`, `__eq__`, `__lt__`, `__le__`, `__gt__`, `__ge__`. Its initializer and path joining methods accept only strings, not os.PathLike objects more broadly.
This is important for supporting *virtual paths*: user subclasses of `_PathBase` that provide access to archive files, FTP servers, etc. In these classes, the above methods should be implemented by users only as appropriate, with due consideration for the hash/equality of any backing objects, such as file objects or sockets.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|