From 89d593bb63aee3425f5a462453e470a1fa6700ee Mon Sep 17 00:00:00 2001 From: Jirka Date: Sun, 1 Oct 2023 14:17:41 +0200 Subject: [PATCH] switch from isort to ruff/I --- .pre-commit-config.yaml | 6 ------ pyproject.toml | 1 + src/deprecate/deprecation.py | 26 +++----------------------- src/deprecate/utils.py | 25 ++++++++++++++++++++++++- 4 files changed, 28 insertions(+), 30 deletions(-) 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/deprecation.py b/src/deprecate/deprecation.py index d429055..23ac72a 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.deprecation 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..14a2426 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, Generator, List, Optional, Type, Union, Callable, Tuple + + +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]]: