Skip to content

Ability to check if a filesystem implements an interface #1411

Open
@lobis

Description

@lobis

Apologies if this is currently possible, I couldn't find a clean way to achieve this.

I think it would be useful to have a way to check if a given filesystem implements a given interface (e.g. is cat_file implemented for the ssh protocol?).

Currently, when calling an interface that is not implemented, a NotImplementedError will be thrown since this method is defined in the base class. Checking if a method with the requested name is present in the class will always return True since it's defined in the base class (but not implemented). I guess there are some workarounds such as using the inspect module but

My use case is a library that uses fsspec for file access and relies on specific interfaces. If the interface is not present for the filesystem it would be nice to throw an exception pointing the user to the specific fsspec protocol and method that needs to be implemented (so they can open an issue to request it, if it makes sense).

This can currently be achieved wrapping the code in a try/except block and checking for NotImplementedError but personally I don't find this solution very clean. In order to avoid wrapping the code one could also add this try/except block on initialization to check if the method is implemented (by calling it with trivial arguments) but this may introduce some delay in the case the method is implemented, which would be most cases so I also don't like this.

There already exists a nice way to check if a protocol is available in fsspec using the registry, I guess this could be an extension to this feature, where the individual filesystems register what interfaces they support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions