Skip to content

Commit 8d193da

Browse files
committed
msg for no target
1 parent 9e83751 commit 8d193da

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

deprecate/deprecation.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
from typing import Any, Callable, Dict, List, Optional, Tuple
44
from warnings import warn
55

6-
#: Template warning message
6+
#: Default template warning message
77
TEMPLATE_WARNING = (
88
"The `%(source_name)s` was deprecated since v%(deprecated_in)s in favor of `%(target_path)s`."
99
" It will be removed in v%(remove_in)s."
1010
)
11+
#: Default template warning message for no target func/method
12+
TEMPLATE_WARNING_NO_TARGET = (
13+
"The `%(source_name)s` was deprecated since v%(deprecated_in)s. It will be removed in v%(remove_in)s."
14+
)
1115

1216
deprecation_warning = partial(warn, category=DeprecationWarning)
1317

@@ -68,7 +72,7 @@ def _raise_warn(
6872
target: Optional[Callable],
6973
deprecated_in: str,
7074
remove_in: str,
71-
template_mgs: str = TEMPLATE_WARNING,
75+
template_mgs: Optional[str] = None,
7276
) -> None:
7377
"""
7478
Raise deprecation warning with in given stream,
@@ -92,8 +96,10 @@ def _raise_warn(
9296
if target:
9397
target_name = target.__name__
9498
target_path = f'{target.__module__}.{target_name}'
99+
template_mgs = TEMPLATE_WARNING if template_mgs is None else template_mgs
95100
else:
96101
target_name, target_path = "", ""
102+
template_mgs = TEMPLATE_WARNING_NO_TARGET if template_mgs is None else template_mgs
97103
source_name = source.__qualname__.split('.')[-2] if source.__name__ == "__init__" else source.__name__
98104
source_path = f'{source.__module__}.{source_name}'
99105
msg_args = dict(
@@ -113,7 +119,7 @@ def deprecated(
113119
remove_in: str = "",
114120
stream: Optional[Callable] = deprecation_warning,
115121
num_warns: int = 1,
116-
template_mgs: str = TEMPLATE_WARNING,
122+
template_mgs: Optional[str] = None,
117123
args_mapping: Optional[Dict[str, str]] = None,
118124
args_extra: Optional[Dict[str, Any]] = None,
119125
) -> Callable:

tests/test_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def depr_pow_wrong(a: int, c: float = 4) -> float:
6464

6565
def test_deprecated_func_warn_only() -> None:
6666
with pytest.deprecated_call(
67-
match='The `depr_sum_warn_only` was deprecated since v0.2 in favor of ``. It will be removed in v0.3.'
67+
match='The `depr_sum_warn_only` was deprecated since v0.2. It will be removed in v0.3.'
6868
):
6969
assert depr_sum_warn_only(2) is None
7070

0 commit comments

Comments
 (0)