diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6e9e696..f804c1b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -35,12 +35,6 @@ repos: # - id: docformatter # args: [--in-place] - - repo: https://github.com/PyCQA/isort - rev: 5.12.0 - hooks: - - id: isort - name: imports - - repo: https://github.com/psf/black rev: 23.3.0 hooks: diff --git a/pyproject.toml b/pyproject.toml index 35f6d34..a18f6b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,6 +70,7 @@ line-length = 120 select = [ "E", "W", # see: https://pypi.org/project/pycodestyle "F", # see: https://pypi.org/project/pyflakes + "I", # isort "D", # see: https://pypi.org/project/pydocstyle "N", # see: https://pypi.org/project/pep8-naming "S", # see: https://pypi.org/project/flake8-bandit diff --git a/src/deprecate/__about__.py b/src/deprecate/__about__.py index d682138..c99e8e7 100644 --- a/src/deprecate/__about__.py +++ b/src/deprecate/__about__.py @@ -1,6 +1,6 @@ """Package details.""" -__version__ = "0.3.2" +__version__ = "0.4.0dev" __docs__ = "Deprecation tooling" __author__ = "Jiri Borovec" __author_email__ = "j.borovec+github[at]gmail.com" diff --git a/src/deprecate/deprecation.py b/src/deprecate/deprecation.py index d429055..5c81f9f 100644 --- a/src/deprecate/deprecation.py +++ b/src/deprecate/deprecation.py @@ -4,9 +4,11 @@ """ import inspect from functools import partial, wraps -from typing import Any, Callable, Dict, List, Optional, Tuple, Union +from typing import Any, Callable, Dict, Optional, Union from warnings import warn +from deprecate.utils import get_func_arguments_types_defaults + #: Default template warning message fot redirecting callable TEMPLATE_WARNING_CALLABLE = ( "The `%(source_name)s` was deprecated since v%(deprecated_in)s in favor of `%(target_path)s`." @@ -27,28 +29,6 @@ deprecation_warning = partial(warn, category=FutureWarning) -def get_func_arguments_types_defaults(func: Callable) -> List[Tuple[str, Tuple, Any]]: - """Parse function arguments, types and default values. - - Args: - func: a function to be xeamined - - Returns: - sequence of details for each position/keyward argument - - Example: - >>> get_func_arguments_types_defaults(get_func_arguments_types_defaults) - [('func', typing.Callable, )] - """ - func_default_params = inspect.signature(func).parameters - func_arg_type_val = [] - for arg in func_default_params: - arg_type = func_default_params[arg].annotation - arg_default = func_default_params[arg].default - func_arg_type_val.append((arg, arg_type, arg_default)) - return func_arg_type_val - - def _update_kwargs_with_args(func: Callable, fn_args: tuple, fn_kwargs: dict) -> dict: """Update in case any args passed move them to kwargs and add defaults. diff --git a/src/deprecate/utils.py b/src/deprecate/utils.py index 2558df6..6f057a5 100644 --- a/src/deprecate/utils.py +++ b/src/deprecate/utils.py @@ -2,9 +2,32 @@ Copyright (C) 2020-2023 Jiri Borovec <...> """ +import inspect import warnings from contextlib import contextmanager -from typing import Any, Generator, List, Optional, Type, Union +from typing import Any, Callable, Generator, List, Optional, Tuple, Type, Union + + +def get_func_arguments_types_defaults(func: Callable) -> List[Tuple[str, Tuple, Any]]: + """Parse function arguments, types and default values. + + Args: + func: a function to be xeamined + + Returns: + sequence of details for each position/keyward argument + + Example: + >>> get_func_arguments_types_defaults(get_func_arguments_types_defaults) + [('func', typing.Callable, )] + """ + func_default_params = inspect.signature(func).parameters + func_arg_type_val = [] + for arg in func_default_params: + arg_type = func_default_params[arg].annotation + arg_default = func_default_params[arg].default + func_arg_type_val.append((arg, arg_type, arg_default)) + return func_arg_type_val def _warns_repr(warns: List[warnings.WarningMessage]) -> List[Union[Warning, str]]: diff --git a/tests/collection_deprecate.py b/tests/collection_deprecate.py index 4577c47..c85e4ba 100644 --- a/tests/collection_deprecate.py +++ b/tests/collection_deprecate.py @@ -1,8 +1,8 @@ """Copyright (C) 2020-2023 Jiri Borovec <...>.""" +from deprecate import deprecated, void from sklearn.metrics import accuracy_score -from deprecate import deprecated, void from tests.collection_targets import base_pow_args, base_sum_kwargs _SHORT_MSG_FUNC = "`%(source_name)s` >> `%(target_name)s` in v%(deprecated_in)s rm v%(remove_in)s." diff --git a/tests/test_classes.py b/tests/test_classes.py index 4dab1c2..97e7fff 100644 --- a/tests/test_classes.py +++ b/tests/test_classes.py @@ -4,9 +4,9 @@ from warnings import warn import pytest - from deprecate.deprecation import deprecated from deprecate.utils import no_warning_call + from tests.collection_targets import NewCls _deprecation_warning = partial(warn, category=DeprecationWarning) diff --git a/tests/test_functions.py b/tests/test_functions.py index a09fec0..5dded1e 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -1,7 +1,7 @@ """Copyright (C) 2020-2023 Jiri Borovec <...>.""" import pytest - from deprecate.utils import no_warning_call + from tests.collection_deprecate import ( depr_accuracy_extra, depr_accuracy_map, diff --git a/tests/test_utils.py b/tests/test_utils.py index a14fec0..57c7de5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,7 +3,6 @@ from warnings import warn import pytest - from deprecate.utils import no_warning_call