fsspec / universal_pathlib

pathlib api extended to use fsspec backends
MIT License
211 stars 36 forks source link

Provide py38-py311 and py312 compatible way for subclassing #172

Closed ap-- closed 4 months ago

ap-- commented 5 months ago

When #152 is merged, user subclasses that override upath.core._FSSpecAccessor will very likely not work correctly with Python3.12, because the 3.12 implementation doesn't use the accessor.

There should be a recommended way for users to subclass UPath for Python3.12 AND Python3.8-Python3.11 without having to maintain two code paths.

Searching GitHub, I could collect an example set of user subclasses that can be split into ~3~ 4 intended use cases:

(1) customize fsspec filesystem creation

here the user wants to change the way the fsspec filesystem instance is created:

upath.UPath should offer a classmethod _make_fs() (?) to allow fsspec filesystem instance customization.

It should be possible too to support old code on python3.12 by detecting when the _default_accessor attribute is present and use that to make a compatible _make_fs() (?) fallback method.

(2) customize path formatting

here the user wants to change the way the path is formatted. Examples:

(3) fix behavior of some accessor methods

here the behavior of a fsspec filesystem method is fixed by fixing the accessor method. Example:

(4) customize storage_options extraction

Not really specific to the Accessor subclassing, because the implementation is overriding __new__ in the UPath subclass. The intention is to extract additional fsspec storage_options from the provided args when instantiating UPath(). Example:

TODO

While this list in not complete, it does cover ~3~ 4 reasonably easy to solve cases for making the transition to 3.12 less bumpy for custom subclasses.