33from typing import Any , Callable , Dict , List , Optional , Tuple
44from warnings import warn
55
6- #: Template warning message
6+ #: Default template warning message
77TEMPLATE_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
1216deprecation_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 :
0 commit comments