Skip to content

Commit

Permalink
switch from isort to ruff/I (#34)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Borda and pre-commit-ci[bot] committed Oct 1, 2023
1 parent cc58214 commit f51fd2c
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 35 deletions.
6 changes: 0 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/deprecate/__about__.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
26 changes: 3 additions & 23 deletions src/deprecate/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`."
Expand All @@ -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, <class 'inspect._empty'>)]
"""
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.
Expand Down
25 changes: 24 additions & 1 deletion src/deprecate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, <class 'inspect._empty'>)]
"""
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]]:
Expand Down
2 changes: 1 addition & 1 deletion tests/collection_deprecate.py
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
2 changes: 1 addition & 1 deletion tests/test_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_functions.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 0 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from warnings import warn

import pytest

from deprecate.utils import no_warning_call


Expand Down

0 comments on commit f51fd2c

Please sign in to comment.