Skip to content

Commit bf57030

Browse files
deepsource-autofix[bot]Bordapre-commit-ci[bot]
authored
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 <Borda@users.noreply.github.com> Co-authored-by: Jirka <jirka.borovec@seznam.cz> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ab24083 commit bf57030

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

deprecate/deprecation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ def packing(source: Callable) -> Callable:
240240
def wrapped_fn(*args: Any, **kwargs: Any) -> Any:
241241
# check if user requested a skip
242242
shall_skip = skip_if() if callable(skip_if) else bool(skip_if)
243-
assert isinstance(shall_skip, bool), "function shall return bool"
243+
if not isinstance(shall_skip, bool):
244+
raise TypeError("User function `shall_skip` shall return bool, but got: %r" % type(shall_skip))
244245
if shall_skip:
245246
return source(*args, **kwargs)
246247

tests/collection_deprecate.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,8 @@ def depr_pow_skip_if_true(base: float, c1: float = 1, nc1: float = 1) -> float:
116116
@deprecated(True, "0.1", "0.2", args_mapping=dict(c1='nc1'), template_mgs=_SHORT_MSG_ARGS, skip_if=lambda: True)
117117
def depr_pow_skip_if_func(base: float, c1: float = 1, nc1: float = 1) -> float:
118118
return base**(c1 - nc1)
119+
120+
121+
@deprecated(True, "0.1", "0.3", args_mapping=dict(c1='nc1'), template_mgs=_SHORT_MSG_ARGS, skip_if=lambda: 42)
122+
def depr_pow_skip_if_func_int(base: float, c1: float = 1, nc1: float = 1) -> float:
123+
return base**(c1 - nc1)

tests/test_functions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
depr_pow_self_twice,
1616
depr_pow_skip_if_false_true,
1717
depr_pow_skip_if_func,
18+
depr_pow_skip_if_func_int,
1819
depr_pow_skip_if_true,
1920
depr_pow_skip_if_true_false,
2021
depr_pow_wrong,
@@ -150,6 +151,9 @@ def test_deprecated_func_skip_if() -> None:
150151
with pytest.deprecated_call(match='Depr: v0.1 rm v0.2 for args: `c1` -> `nc1`.'):
151152
assert depr_pow_skip_if_false_true(2, c1=2) == 0.5
152153

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

154158
def test_deprecated_func_mapping() -> None:
155159
"""Test mapping to external functions"""

0 commit comments

Comments
 (0)