diff --git a/requirements.txt b/requirements.txt --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ vcversioner aiohttp tenacity +typing_extensions diff --git a/swh/storage/__init__.py b/swh/storage/__init__.py --- a/swh/storage/__init__.py +++ b/swh/storage/__init__.py @@ -6,6 +6,7 @@ import warnings from . import storage +from .interface import StorageInterface Storage = storage.Storage @@ -19,7 +20,7 @@ } -def get_storage(cls, **kwargs): +def get_storage(cls, **kwargs) -> StorageInterface: """Get a storage object of class `storage_class` with arguments `storage_args`. @@ -49,20 +50,27 @@ if cls == 'pipeline': return get_storage_pipeline(**kwargs) - if cls == 'remote': - from .api.client import RemoteStorage as Storage + elif cls == 'remote': + from .api.client import RemoteStorage + return RemoteStorage(**kwargs) # type: ignore # autogenerated methods elif cls == 'local': from .storage import Storage + return Storage(**kwargs) elif cls == 'memory': - from .in_memory import InMemoryStorage as Storage + from .in_memory import InMemoryStorage + return InMemoryStorage(**kwargs) elif cls == 'filter': - from .filter import FilteringProxyStorage as Storage + from .filter import FilteringProxyStorage + return FilteringProxyStorage(**kwargs) elif cls == 'buffer': - from .buffer import BufferingProxyStorage as Storage + from .buffer import BufferingProxyStorage + return BufferingProxyStorage(**kwargs) elif cls == 'retry': - from .retry import RetryingProxyStorage as Storage - - return Storage(**kwargs) + from .retry import RetryingProxyStorage + return RetryingProxyStorage(**kwargs) + else: + # Mismatch between STORAGE_IMPLEMENTATION and this function? + assert False def get_storage_pipeline(steps): diff --git a/swh/storage/interface.py b/swh/storage/interface.py --- a/swh/storage/interface.py +++ b/swh/storage/interface.py @@ -5,10 +5,12 @@ from typing import Any, Dict, List, Optional +from typing_extensions import Protocol + from swh.core.api import remote_api_endpoint -class StorageInterface: +class StorageInterface(Protocol): @remote_api_endpoint('check_config') def check_config(self, *, check_write): """Check that the storage is configured and ready to go."""