diff --git a/kedro/extras/datasets/geopandas/__init__.py b/kedro/extras/datasets/geopandas/__init__.py index 8a8f9e8101..966577fc37 100644 --- a/kedro/extras/datasets/geopandas/__init__.py +++ b/kedro/extras/datasets/geopandas/__init__.py @@ -1,4 +1,4 @@ -"""``GeoJSONLocalDataset`` is an ``AbstractVersionedDataSet`` to save and load GeoJSON files. +"""``GeoJSONDataSet`` is an ``AbstractVersionedDataSet`` to save and load GeoJSON files. """ __all__ = ["GeoJSONDataSet"] diff --git a/kedro/io/__init__.py b/kedro/io/__init__.py index 112d90d809..5899f904c6 100644 --- a/kedro/io/__init__.py +++ b/kedro/io/__init__.py @@ -1,16 +1,14 @@ """``kedro.io`` provides functionality to read and write to a number of data sets. At the core of the library is the ``AbstractDataSet`` class. """ +from __future__ import annotations from .cached_dataset import CachedDataSet, CachedDataset from .core import ( AbstractDataSet, AbstractVersionedDataSet, - DataSetAlreadyExistsError, DatasetAlreadyExistsError, - DataSetError, DatasetError, - DataSetNotFoundError, DatasetNotFoundError, Version, ) @@ -24,6 +22,22 @@ PartitionedDataset, ) +# https://github.com/pylint-dev/pylint/issues/4300#issuecomment-1043601901 +DataSetError: type[Exception] +DataSetNotFoundError: type[DatasetError] +DataSetAlreadyExistsError: type[DatasetError] + + +def __getattr__(name): + import kedro.io.core # pylint: disable=import-outside-toplevel + + if name in ( + kedro.io.core._DEPRECATED_ERROR_CLASSES # pylint: disable=protected-access + ): + return getattr(kedro.io.core, name) + raise AttributeError(f"module {repr(__name__)} has no attribute {repr(name)}") + + __all__ = [ "AbstractDataSet", "AbstractVersionedDataSet", diff --git a/kedro/io/core.py b/kedro/io/core.py index 1387812eef..fd90d25b8f 100644 --- a/kedro/io/core.py +++ b/kedro/io/core.py @@ -20,7 +20,7 @@ from cachetools import Cache, cachedmethod from cachetools.keys import hashkey -from kedro.utils import DeprecatedClassMeta, load_obj +from kedro.utils import load_obj warnings.simplefilter("default", DeprecationWarning) @@ -31,6 +31,11 @@ PROTOCOL_DELIMITER = "://" CLOUD_PROTOCOLS = ("s3", "s3n", "s3a", "gcs", "gs", "adl", "abfs", "abfss", "gdrive") +# https://github.com/pylint-dev/pylint/issues/4300#issuecomment-1043601901 +DataSetError: type[Exception] +DataSetNotFoundError: type[DatasetError] +DataSetAlreadyExistsError: type[DatasetError] + class DatasetError(Exception): """``DatasetError`` raised by ``AbstractDataSet`` implementations @@ -43,12 +48,6 @@ class DatasetError(Exception): pass -class DataSetError(metaclass=DeprecatedClassMeta): - # pylint: disable=missing-class-docstring, too-few-public-methods - - _DeprecatedClassMeta__alias = DatasetError - - class DatasetNotFoundError(DatasetError): """``DatasetNotFoundError`` raised by ``DataCatalog`` class in case of trying to use a non-existing data set. @@ -57,12 +56,6 @@ class DatasetNotFoundError(DatasetError): pass -class DataSetNotFoundError(metaclass=DeprecatedClassMeta): - # pylint: disable=missing-class-docstring, too-few-public-methods - - _DeprecatedClassMeta__alias = DatasetNotFoundError - - class DatasetAlreadyExistsError(DatasetError): """``DatasetAlreadyExistsError`` raised by ``DataCatalog`` class in case of trying to add a data set which already exists in the ``DataCatalog``. @@ -71,10 +64,24 @@ class DatasetAlreadyExistsError(DatasetError): pass -class DataSetAlreadyExistsError(metaclass=DeprecatedClassMeta): - # pylint: disable=missing-class-docstring, too-few-public-methods +_DEPRECATED_ERROR_CLASSES = { + "DataSetError": DatasetError, + "DataSetNotFoundError": DatasetNotFoundError, + "DataSetAlreadyExistsError": DatasetAlreadyExistsError, +} - _DeprecatedClassMeta__alias = DatasetAlreadyExistsError + +def __getattr__(name): + if name in _DEPRECATED_ERROR_CLASSES: + alias = _DEPRECATED_ERROR_CLASSES[name] + warnings.warn( + f"{repr(name)} has been renamed to {repr(alias.__name__)}, " + f"and the alias will be removed in Kedro 0.19.0", + DeprecationWarning, + stacklevel=2, + ) + return alias + raise AttributeError(f"module {repr(__name__)} has no attribute {repr(name)}") class VersionNotFoundError(DatasetError): diff --git a/tests/io/test_core.py b/tests/io/test_core.py index 64e0f3d6dd..05a3204639 100644 --- a/tests/io/test_core.py +++ b/tests/io/test_core.py @@ -1,5 +1,6 @@ from __future__ import annotations +import importlib from decimal import Decimal from fractions import Fraction from pathlib import PurePosixPath @@ -7,7 +8,12 @@ import pytest -from kedro.io.core import AbstractDataSet, _parse_filepath, get_filepath_str +from kedro.io.core import ( + _DEPRECATED_ERROR_CLASSES, + AbstractDataSet, + _parse_filepath, + get_filepath_str, +) # List sourced from https://docs.python.org/3/library/stdtypes.html#truth-value-testing. # Excludes None, as None values are not shown in the str representation. @@ -27,6 +33,13 @@ ] +@pytest.mark.parametrize("module_name", ["kedro.io", "kedro.io.core"]) +@pytest.mark.parametrize("class_name", _DEPRECATED_ERROR_CLASSES) +def test_deprecation(module_name, class_name): + with pytest.warns(DeprecationWarning, match=f"{repr(class_name)} has been renamed"): + getattr(importlib.import_module(module_name), class_name) + + class MyDataSet(AbstractDataSet): def __init__(self, var=None): self.var = var