Skip to content
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

Heads up: pathlib._PathBase may be coming soon #114

Open
barneygale opened this issue Jul 6, 2023 · 3 comments
Open

Heads up: pathlib._PathBase may be coming soon #114

barneygale opened this issue Jul 6, 2023 · 3 comments
Labels
compatibility Compatibility with stdlib pathlib

Comments

@barneygale
Copy link

barneygale commented Jul 6, 2023

I've logged a CPython PR that adds a private pathlib._VirtualPath class:

python/cpython#106337

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 universal_pathlib? It would be great to hear your feedback, thank you.

@ap--
Copy link
Collaborator

ap-- commented Jul 7, 2023

Hi @barneygale

Thank you for the heads up ❤️

I'll provide more detailed comments in the next days. One immediate thought would be, that

from pathlib import Path, _VirtualPath

class UPath(_VirtualPath):
    ...

assert isinstance(UPath, Path)  # will be False

which won't allow users to use UPath instances in code that is guarded via isinstance(p, Path). But I'll think about it more over the weekend and report back.




Currently, I've been working on an update to universal_pathlib based on the 3.12 pathlib, where I introduce:

class PureFSSpecPath(PurePath):  # handles fsspec URI style paths
    _flavour = fsspecpath  # flavour for fsspec
    ...

class UPath(Path):
    __new__ = ... # dispatches to FSSpecUPath if virtual, else PosixUPath or WindowsUPath

class PosixUPath(UPath, PosixPath):  # shim to have localpaths also be instances of UPath
    __slots__ = ()

class WindowsUPath(UPath, WindowsPath):  # shim ...
    __slots__ = ()

class FSSpecUpath(UPath, PureFSSpecUPath):  # base class for virtual (fsspec based) filesystems.
    __new__ = ...  # dispatches to the filesystem specific implementations

But I don't pass all the tests for the implementations yet, which is why it's not ready yet. I've pushed it to https://github.com/ap--/universal_pathlib/tree/pathlib-update, see: upath.core and upath._flavour

Cheers,
Andreas 😃

@ap-- ap-- changed the title Heads up: pathlib.VirtualPath may be coming soon Heads up: pathlib._PathBase may be coming soon Jul 19, 2023
@ap--
Copy link
Collaborator

ap-- commented Jul 19, 2023

VirtualPath -> _PathBase
see: https://discuss.python.org/t/make-pathlib-extensible/3428/134

@ap-- ap-- added the compatibility Compatibility with stdlib pathlib label Aug 28, 2023
@barneygale
Copy link
Author

barneygale commented Dec 27, 2023

Hey - I've published CPython's private PathBase class 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 PathBase public in Python itself. I'd really appreciate any feedback you might have :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Compatibility with stdlib pathlib
Projects
None yet
Development

No branches or pull requests

2 participants