fsspec / universal_pathlib

pathlib api extended to use fsspec backends
MIT License
251 stars 44 forks source link

subclassing from UPath #26

Closed brl0 closed 3 years ago

brl0 commented 3 years ago

Not sure if I am doing this properly, but subclassing UPath is challenging, in part due to this check in the __new__ method:

https://github.com/Quansight/universal_pathlib/blob/dbc57f7ec4c8bb8b2e22975f6b62e25b2b82ecff/upath/core.py#L12

I am curious if this could be changed to:

        if issubclass(cls, UPath):

This would return True even for issubclass(UPath, UPath).

Happy to submit a PR if you are ok with this change.

My surprisingly challenging attempt to subclass UPath to add some convenience methods has really grown my appreciation for what this project has accomplished.

On a related note, after digging deeper into the code, and exploring the pathlib implementation, I am wondering if UPath would benefit from having something like a _URI_Flavour derived from the pathlib._Flavour class. This might make it easier to have consistent path handling across the fsspec based implementations.

andrewfulton9 commented 3 years ago

It it can pass all the tests, I don't see any reason why that couldn't be merged. Please do submit a PR.

I'm interested in the _URI_Flavour idea too, but should probably be in a different issue. Would you mind opening another for that?