Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 1, 2023
1 parent 2919bbd commit 7d6aa22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/deprecate/deprecation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Deprecated wrapper.
Copyright (C) 2020-2023 Jiri Borovec <...>
"""
import inspect
from functools import partial, wraps
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}"
Expand Down Expand Up @@ -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__
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions src/deprecate/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Handy tools for deprecations.
Copyright (C) 2020-2023 Jiri Borovec <...>
"""
import inspect
import warnings
Expand All @@ -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, <class 'inspect._empty'>)]
"""
func_default_params = inspect.signature(func).parameters
func_arg_type_val = []
Expand All @@ -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.
Expand Down Expand Up @@ -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

0 comments on commit 7d6aa22

Please sign in to comment.