81) -> Callable[[TFunc], TFunc]:
82 """Decorator to indicate that a function should not be used
83
84 Parameters
85 ----------
86 reason : str
87 A string explaining why the function should not be used
88 warn_once_per_call : bool
89 If True, only warn once per call location, default True
90 print_context: bool
91 If True, print the calling context as part of the warning, default False
92 """
93
94
95 warncache: set[tuple[int, str, int]] =
set()
96
97 def deprecate_decorator(f):
98 @functools.wraps(f)
99 def call_deprecated(*args, **kwargs):
100 """Call a deprecated function"""
101
102
103
104 frame_info = inspect.stack()[1]
105 cache_value = id(f), frame_info.filename, frame_info.lineno
106 if not warn_once_per_call or cache_value not in warncache:
107 if warn_once_per_call:
108 warncache.add(cache_value)
109 log.warning(f"Calling deprecated function '{f.__qualname__}'")
110 log.warning(
111 f"in function {frame_info.function}, file {frame_info.filename}, line {frame_info.lineno}"
112 )
113 if print_context:
114 for idx, line in enumerate(frame_info.code_context):
115 log.warning(f"{frame_info.lineno + idx - frame_info.index}\t{line}")
116 log.warning(reason)
117 return f(*args, **kwargs)
118 return call_deprecated
119 return deprecate_decorator