Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

precommit: enable docformatter #36

Merged
merged 4 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ repos:
additional_dependencies: [tomli]
#args: ["--write-changes"] # uncomment if you want to get automatic fixing

#- repo: https://github.com/PyCQA/docformatter
# rev: v1.5.1
# hooks:
# - id: docformatter
# args: [--in-place]
- repo: https://github.com/PyCQA/docformatter
rev: v1.5.1
hooks:
- id: docformatter
additional_dependencies: [tomli]
args: [--in-place]

- repo: https://github.com/psf/black
rev: 23.3.0
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ quiet-level = 3
#ignore-words-list = ""


[tool.docformatter]
recursive = true
# this need to be shorter as some docstings are r"""...
wrap-summaries = 119
wrap-descriptions = 120
blank = true


[tool.black]
# https://github.com/psf/black
line-length = 120
Expand Down
7 changes: 7 additions & 0 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 Down Expand Up @@ -191,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
3 changes: 3 additions & 0 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
Loading