Skip to content

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

@ap--

Description

@ap--

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.

  • (ALL) detect custom _accessor in py3.12 classes and provide warning with instructions on how to migrate.
  • (1) provide customizable fsspec filesystem factory classmethod
  • (2) provide instructions for how to migrate to .path (with potential customization)
  • (3) recommend overriding UPath.mkdir, etc... directly.
  • (4) provide customizable fsspec storage_option extraction classmethod

Metadata

Metadata

Assignees

Labels

bug 🐛Something isn't workingcompatibility 🤝Compatibility with stdlib pathlib

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions