You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Heads up: pathlib.VirtualPath may be coming soon #347
If/when that lands, it's not much more work to drop the underscore and introduce pathlib.VirtualPath to the world. This would be Python 3.13 at the earliest.
Would it be suitable for use in cloudpathlib? It would be great to have your feedback
If the PyPI package succeeds and matures, I'm hopeful we can make PathBase public in Python itself. Hopefully you can make it work, do let me know if not!
If the PathBase does get adopted in the standard library in upcoming releases, using that as the base class for CloudPath would make adoption of this package all the more powerful.
@barneygale not that you have to provide this, but would you be able to provide another limited implementation example (in addition to TarPath) for something like S3Path or something to that effect?
I saw that python/cpython#106337 got merged. Does that mean that the private pathlib._PathBase will definitely be released with Python 3.13 later this year? Does that mean we should treat pathlib-abc as a backport rather than a prototype?
It would be great if you have documentation coming about the benefits of using PathBase.
Is the benefit mainly that we'd be able to reduce the amount of code we have by inheriting methods from PathBase instead?
We also struggle a lot with typechecking—we want to have some kind of common denominator AnyPath that pathlib and cloudpathlib types would subtype. Is this something PathBase might be able to help with?
Does that mean that the private pathlib._PathBase will definitely be released with Python 3.13 later this year? Does that mean we should treat pathlib-abc as a backport rather than a prototype?
The cut-off date for new features in 3.13 is May this year. It's possible but unlikely that PathBase will be made public in time. I think 3.14 or 3.15 is a more likely timeframe. Things can move slowly in CPython development!
I think you should treat pathlib-abc as a prototype at the moment. It will become a backport once this stuff is public in CPython. I appreciate the PyPI package description is misleading - will fix.
It would be great if you have documentation coming about the benefits of using PathBase.
Is the benefit mainly that we'd be able to reduce the amount of code we have by inheriting methods from PathBase instead?
Pretty much. You get all the PurePath behaviour, plus a few high-level methods like glob() and read_text() that are implemented in terms of lower-level abstract methods.
We also struggle a lot with typechecking—we want to have some kind of common denominator AnyPath that pathlib and cloudpathlib types would subtype. Is this something PathBase might be able to help with?
That's the ultimate goal, yeah. Once PathBase is in CPython, you'll be able to write:
This doesn't work with the PyPI package because pathlib.Path isn't a subclass of pathlib_abc.PathBase. Perhaps that's solvable with some temporary __instancecheck__() magic?
Looks like it's fairly simple to make pathlib classes virtual subclasses of the ABCs:
diff --git a/pathlib_abc/__init__.py b/pathlib_abc/__init__.py
index db9ac15..aa5718e 100644
--- a/pathlib_abc/__init__.py+++ b/pathlib_abc/__init__.py@@ -1,3 +1,4 @@+import abc
import functools
ntpath = object()
from . import _posixpath as posixpath
@@ -169,7 +170,7 @@ class _PathParents(Sequence):
return "<{}.parents>".format(type(self._path).__name__)
-class PurePathBase:+class PurePathBase(abc.ABC):
"""Base class for pure path objects.
This class *does not* provide several magic methods that are defined in
@@ -1143,3 +1144,8 @@ class PathBase(PurePathBase):
def as_uri(self):
"""Return the path as a URI."""
self._unsupported("as_uri")
+++import pathlib+PurePathBase.register(pathlib.PurePath)+PathBase.register(pathlib.Path)
hello, it looks like this PR (python/cpython#106337) has been merged into cpython. @barneygale does that mean pathlib_abc can be considered reliable enough to be used as a backported solution as @jayqi asked?
I don't think this is stable enough for us to depend on for cloudpathlib. Looking at the pathlib source code in the cpython repository and looking at pathlib-abc, there are still pretty drastic changes to the interface happening. Just last month, PurePathBase and PathBase were refactored into JoinablePath, ReadablePath, and WritablePath. It also looks like these interfaces are still private in Python 3.14 so far.
Hey @barneygale could you weigh in on the issue of less stable interfaces that @jayqi pointed out? and do you think the POC I put up in PR is roughly the approach we'd want to take to implement these interfaces?
Activity
barneygale commentedon Dec 27, 2023
Hello - I've published CPython's private
PathBaseclass in a PyPI package: https://pypi.org/project/pathlib-abc/0.1.0/. No docs yet but I should have them ready soon.If the PyPI package succeeds and matures, I'm hopeful we can make
PathBasepublic in Python itself. Hopefully you can make it work, do let me know if not!rpmcginty commentedon Jan 3, 2024
If the
PathBasedoes get adopted in the standard library in upcoming releases, using that as the base class forCloudPathwould make adoption of this package all the more powerful.@barneygale not that you have to provide this, but would you be able to provide another limited implementation example (in addition to
TarPath) for something likeS3Pathor something to that effect?barneygale commentedon Jan 4, 2024
Here's a basic example:
Would it be useful for me to add
stat()anditerdir()too?jayqi commentedon Jan 4, 2024
Hi @barneygale,
Very cool!
I saw that python/cpython#106337 got merged. Does that mean that the private
pathlib._PathBasewill definitely be released with Python 3.13 later this year? Does that mean we should treat pathlib-abc as a backport rather than a prototype?It would be great if you have documentation coming about the benefits of using
PathBase.Is the benefit mainly that we'd be able to reduce the amount of code we have by inheriting methods from
PathBaseinstead?We also struggle a lot with typechecking—we want to have some kind of common denominator
AnyPaththat pathlib and cloudpathlib types would subtype. Is this somethingPathBasemight be able to help with?barneygale commentedon Jan 4, 2024
The cut-off date for new features in 3.13 is May this year. It's possible but unlikely that
PathBasewill be made public in time. I think 3.14 or 3.15 is a more likely timeframe. Things can move slowly in CPython development!I think you should treat pathlib-abc as a prototype at the moment. It will become a backport once this stuff is public in CPython. I appreciate the PyPI package description is misleading - will fix.
Pretty much. You get all the
PurePathbehaviour, plus a few high-level methods likeglob()andread_text()that are implemented in terms of lower-level abstract methods.That's the ultimate goal, yeah. Once
PathBaseis in CPython, you'll be able to write:Or if you don't care about accepting strings/arbitrary pathlike objects:
This doesn't work with the PyPI package because
pathlib.Pathisn't a subclass ofpathlib_abc.PathBase. Perhaps that's solvable with some temporary__instancecheck__()magic?barneygale commentedon Jan 4, 2024
Looks like it's fairly simple to make
pathlibclasses virtual subclasses of the ABCs:rpmcginty commentedon Apr 21, 2025
hello, it looks like this PR (python/cpython#106337) has been merged into cpython. @barneygale does that mean pathlib_abc can be considered reliable enough to be used as a backported solution as @jayqi asked?
jayqi commentedon Apr 27, 2025
I don't think this is stable enough for us to depend on for cloudpathlib. Looking at the pathlib source code in the cpython repository and looking at pathlib-abc, there are still pretty drastic changes to the interface happening. Just last month,
PurePathBaseandPathBasewere refactored intoJoinablePath,ReadablePath, andWritablePath. It also looks like these interfaces are still private in Python 3.14 so far.rpmcginty commentedon Apr 30, 2025
yeah I saw that. of course, if we can get guidance from @barneygale, it could help!
I added a quick poc approach to making the
CloudPathimplement the path interface: #517rpmcginty commentedon Jul 22, 2025
Hey @barneygale could you weigh in on the issue of less stable interfaces that @jayqi pointed out? and do you think the POC I put up in PR is roughly the approach we'd want to take to implement these interfaces?
rpmcginty commentedon Feb 2, 2026
@barneygale do you have any comments for the stability of the interfaces and when this would be released as public in standard python release?