diff --git a/deep_utils/__init__.py b/deep_utils/__init__.py index c610bf9b..ac22bdda 100644 --- a/deep_utils/__init__.py +++ b/deep_utils/__init__.py @@ -4,7 +4,7 @@ from .utils.lib_utils.integeration_utils import import_lazy_module # Deep Utils version number -__version__ = "1.3.42" +__version__ = "1.3.43" from .utils.constants import DUMMY_PATH, Backends diff --git a/deep_utils/utils/decorators/main.py b/deep_utils/utils/decorators/main.py index 6c0e119d..93129e4b 100644 --- a/deep_utils/utils/decorators/main.py +++ b/deep_utils/utils/decorators/main.py @@ -1,3 +1,4 @@ +import logging import time from functools import wraps from typing import Callable @@ -24,6 +25,23 @@ def wrapper(self, *args, **kwargs): return wrapper +def method_deprecated(method, version: str = "") -> Callable: + """ + Add a deprecated warning + :param method: The method that will be measured + :param version: In which version it will be deprecated + :return: + """ + + @wraps(method) + def wrapper(self, *args, **kwargs): + logging.warning(f"This method: {method.__name__} is deprecated. {f'This will be removed in version: {version}!' if version else 'This will be removed in the upcoming releases!'}") + results = method(self, *args, **kwargs) + return results + + return wrapper + + def get_func_time(func) -> Callable: """ Gets the elapsed time of a class diff --git a/deep_utils/utils/json_utils/json_utils.py b/deep_utils/utils/json_utils/json_utils.py index 6fbe034b..2d1142db 100644 --- a/deep_utils/utils/json_utils/json_utils.py +++ b/deep_utils/utils/json_utils/json_utils.py @@ -2,10 +2,12 @@ from typing import Union from pathlib import Path +from deep_utils.utils.decorators.main import method_deprecated + class JsonUtils: @staticmethod - def load_json(json_path: Union[str, Path], encoding="utf-8") -> dict: + def load(json_path: Union[str, Path], encoding="utf-8") -> dict: """ loads a json file :param json_path: Path to json file to load @@ -18,7 +20,7 @@ def load_json(json_path: Union[str, Path], encoding="utf-8") -> dict: return json_data @staticmethod - def dump_json( + def dump( json_path: Union[str, Path], json_object: Union[list, dict], encoding="utf-8", ensure_ascii=True ) -> None: """ @@ -35,3 +37,7 @@ def dump_json( with open(json_path, mode="w", encoding=encoding) as f: json.dump(json_object, f, ensure_ascii=ensure_ascii) + + +JsonUtils.load_json = method_deprecated(JsonUtils.load) +JsonUtils.dump_json = method_deprecated(JsonUtils.dump) diff --git a/deep_utils/utils/pickle_utils/pickle_utils.py b/deep_utils/utils/pickle_utils/pickle_utils.py index 02da453a..dbad2701 100644 --- a/deep_utils/utils/pickle_utils/pickle_utils.py +++ b/deep_utils/utils/pickle_utils/pickle_utils.py @@ -1,14 +1,20 @@ import pickle +from deep_utils.utils.decorators.main import method_deprecated + class PickleUtils: @staticmethod - def dump_pickle(file_path: str, file, mode: str = "wb"): + def dump(file_path: str, file, mode: str = "wb"): with open(file_path, mode=mode) as f: pickle.dump(file, f) @staticmethod - def load_pickle(file_path: str, mode: str = "rb", encoding=""): + def load(file_path: str, mode: str = "rb", encoding=""): with open(file_path, mode=mode) as f: return pickle.load(f, encoding=encoding) + + +PickleUtils.load_pickle = method_deprecated(PickleUtils.load) +PickleUtils.dump_pickle = method_deprecated(PickleUtils.dump) diff --git a/setup.py b/setup.py index 7d14b8f4..e1721526 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ import setuptools -VERSION = "1.3.42" +VERSION = "1.3.43" long_description = open("Readme.md", mode="r", encoding="utf-8").read()