Skip to content

Commit

Permalink
Remove assert statement from non-test files (#7)
Browse files Browse the repository at this point in the history
* Remove assert statement from non-test files
* add test

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: Jirka <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Jun 11, 2021
1 parent ab24083 commit bf57030
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion deprecate/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def packing(source: Callable) -> Callable:
def wrapped_fn(*args: Any, **kwargs: Any) -> Any:
# check if user requested a skip
shall_skip = skip_if() if callable(skip_if) else bool(skip_if)
assert isinstance(shall_skip, bool), "function shall return bool"
if not isinstance(shall_skip, bool):
raise TypeError("User function `shall_skip` shall return bool, but got: %r" % type(shall_skip))
if shall_skip:
return source(*args, **kwargs)

Expand Down
5 changes: 5 additions & 0 deletions tests/collection_deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,8 @@ def depr_pow_skip_if_true(base: float, c1: float = 1, nc1: float = 1) -> float:
@deprecated(True, "0.1", "0.2", args_mapping=dict(c1='nc1'), template_mgs=_SHORT_MSG_ARGS, skip_if=lambda: True)
def depr_pow_skip_if_func(base: float, c1: float = 1, nc1: float = 1) -> float:
return base**(c1 - nc1)


@deprecated(True, "0.1", "0.3", args_mapping=dict(c1='nc1'), template_mgs=_SHORT_MSG_ARGS, skip_if=lambda: 42)
def depr_pow_skip_if_func_int(base: float, c1: float = 1, nc1: float = 1) -> float:
return base**(c1 - nc1)
4 changes: 4 additions & 0 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
depr_pow_self_twice,
depr_pow_skip_if_false_true,
depr_pow_skip_if_func,
depr_pow_skip_if_func_int,
depr_pow_skip_if_true,
depr_pow_skip_if_true_false,
depr_pow_wrong,
Expand Down Expand Up @@ -150,6 +151,9 @@ def test_deprecated_func_skip_if() -> None:
with pytest.deprecated_call(match='Depr: v0.1 rm v0.2 for args: `c1` -> `nc1`.'):
assert depr_pow_skip_if_false_true(2, c1=2) == 0.5

with pytest.raises(TypeError, match="User function `shall_skip` shall return bool, but got: <class 'int'>"):
assert depr_pow_skip_if_func_int(2, c1=2)


def test_deprecated_func_mapping() -> None:
"""Test mapping to external functions"""
Expand Down

0 comments on commit bf57030

Please sign in to comment.