From bf57030a4163413a5eb1d3be62d8887a7a889650 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 11 Jun 2021 11:17:43 +0200 Subject: [PATCH] Remove assert statement from non-test files (#7) * 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 Co-authored-by: Jirka Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- deprecate/deprecation.py | 3 ++- tests/collection_deprecate.py | 5 +++++ tests/test_functions.py | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/deprecate/deprecation.py b/deprecate/deprecation.py index fc868f7..9be3d92 100644 --- a/deprecate/deprecation.py +++ b/deprecate/deprecation.py @@ -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) diff --git a/tests/collection_deprecate.py b/tests/collection_deprecate.py index ba6b6d2..478a2df 100644 --- a/tests/collection_deprecate.py +++ b/tests/collection_deprecate.py @@ -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) diff --git a/tests/test_functions.py b/tests/test_functions.py index cda45f2..797b69d 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -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, @@ -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: "): + assert depr_pow_skip_if_func_int(2, c1=2) + def test_deprecated_func_mapping() -> None: """Test mapping to external functions"""