diff --git a/xarray/backends/common.py b/xarray/backends/common.py index 1ac988c6b4f..6abe89e219f 100644 --- a/xarray/backends/common.py +++ b/xarray/backends/common.py @@ -4,6 +4,7 @@ import os import time import traceback +from abc import ABC, abstractmethod from collections.abc import Iterable from glob import glob from typing import TYPE_CHECKING, Any, ClassVar @@ -170,17 +171,20 @@ def get_duck_array(self, dtype: np.typing.DTypeLike = None): return self[key] # type: ignore [index] -class AbstractDataStore: +class AbstractDataStore(ABC): __slots__ = () - def get_dimensions(self): # pragma: no cover - raise NotImplementedError() + @abstractmethod + def get_dimensions(self): + ... - def get_attrs(self): # pragma: no cover - raise NotImplementedError() + @abstractmethod + def get_attrs(self): + ... - def get_variables(self): # pragma: no cover - raise NotImplementedError() + @abstractmethod + def get_variables(self): + ... def get_encoding(self): return {} @@ -300,14 +304,13 @@ def encode_attribute(self, a): """encode one attribute""" return a - def set_dimension(self, dim, length): # pragma: no cover - raise NotImplementedError() + @abstractmethod + def set_dimension(self, dim, length): + ... - def set_attribute(self, k, v): # pragma: no cover - raise NotImplementedError() - - def set_variable(self, k, v): # pragma: no cover - raise NotImplementedError() + @abstractmethod + def set_attribute(self, k, v): + ... def store_dataset(self, dataset): """ @@ -444,7 +447,7 @@ def encode(self, variables, attributes): return variables, attributes -class BackendEntrypoint: +class BackendEntrypoint(ABC): """ ``BackendEntrypoint`` is a class container and it is the main interface for the backend plugins, see :ref:`RST backend_entrypoint`. @@ -485,6 +488,7 @@ def __repr__(self) -> str: txt += f"\n Learn more at {self.url}" return txt + @abstractmethod def open_dataset( self, filename_or_obj: str | os.PathLike[Any] | BufferedIOBase | AbstractDataStore, @@ -495,8 +499,7 @@ def open_dataset( """ Backend open_dataset method used by Xarray in :py:func:`~xarray.open_dataset`. """ - - raise NotImplementedError + ... def guess_can_open( self,