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

switch from isort to ruff/I #34

Merged
merged 4 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
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
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.deprecation import get_func_arguments_types_defaults
Fixed Show fixed Hide fixed

#: 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
Loading