From 7d6aa22348bf684d6ace9d367d3ea9160362493d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 1 Oct 2023 13:08:37 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/deprecate/deprecation.py | 10 ++++++++-- src/deprecate/utils.py | 7 ++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/deprecate/deprecation.py b/src/deprecate/deprecation.py index 6be9e85..1d22492 100644 --- a/src/deprecate/deprecation.py +++ b/src/deprecate/deprecation.py @@ -1,6 +1,7 @@ """Deprecated wrapper. Copyright (C) 2020-2023 Jiri Borovec <...> + """ import inspect from functools import partial, wraps @@ -39,6 +40,7 @@ def _update_kwargs_with_args(func: Callable, fn_args: tuple, fn_kwargs: dict) -> Returns: extended dictionary with all args as keyword arguments + """ if not fn_args: return fn_kwargs @@ -59,6 +61,7 @@ def _update_kwargs_with_defaults(func: Callable, fn_kwargs: dict) -> dict: Returns: extended dictionary with all args as keyword arguments + """ func_arg_type_val = get_func_arguments_types_defaults(func) # fill by source defaults @@ -74,6 +77,7 @@ def _raise_warn(stream: Callable, source: Callable, template_mgs: str, **extras: source: function/methods which is wrapped template_mgs: python formatted string message which has build-ins arguments extras: string arguments used in the template message + """ source_name = source.__qualname__.split(".")[-2] if source.__name__ == "__init__" else source.__name__ source_path = f"{source.__module__}.{source_name}" @@ -105,6 +109,7 @@ def _raise_warn_callable( - ``target_path`` pythonic path to the function such as "any_package.with_module.my_target_func" - ``deprecated_in`` version passed to wrapper - ``remove_in`` version passed to wrapper + """ if callable(target): target_name = target.__name__ @@ -147,6 +152,7 @@ def _raise_warn_arguments( - ``argument_map`` mapping from deprecated to new argument "old_arg -> new_arg" - ``deprecated_in`` version passed to wrapper - ``remove_in`` version passed to wrapper + """ args_map = ", ".join([TEMPLATE_ARGUMENT_MAPPING % {"old_arg": a, "new_arg": b} for a, b in arguments.items()]) template_mgs = template_mgs or TEMPLATE_WARNING_ARGUMENTS @@ -164,8 +170,7 @@ def deprecated( args_extra: Optional[Dict[str, Any]] = None, skip_if: Union[bool, Callable] = False, ) -> Callable: - """Decorate a function or class with warning message and pass all arguments - directly to the target class/method. + """Decorate a function or class with warning message and pass all arguments directly to the target class/method. Args: target: Function or method to forward the call. If set ``None``, no forwarding is applied and only warn. @@ -192,6 +197,7 @@ def deprecated( Raises: TypeError: if there are some argument in source function which are missing in target function + """ def packing(source: Callable) -> Callable: diff --git a/src/deprecate/utils.py b/src/deprecate/utils.py index aedf7e3..c11ea06 100644 --- a/src/deprecate/utils.py +++ b/src/deprecate/utils.py @@ -1,6 +1,7 @@ """Handy tools for deprecations. Copyright (C) 2020-2023 Jiri Borovec <...> + """ import inspect import warnings @@ -20,6 +21,7 @@ def get_func_arguments_types_defaults(func: Callable) -> List[Tuple[str, Tuple, 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 = [] @@ -44,6 +46,7 @@ def no_warning_call(warning_type: Optional[Type[Warning]] = None, match: Optiona Raises: AssertionError: if specified warning was called + """ with warnings.catch_warnings(record=True) as called: # Cause all warnings to always be triggered. @@ -73,7 +76,5 @@ def no_warning_call(warning_type: Optional[Type[Warning]] = None, match: Optiona def void(*args: Any, **kwrgs: Any) -> Any: - """Empty function which does nothing, just let your IDE stop complaining - about unused arguments. - """ + """Empty function which does nothing, just let your IDE stop complaining about unused arguments.""" _, _ = args, kwrgs