@@ -205,114 +205,6 @@ def wrapper(*args, **kwargs):
205
205
return decorator
206
206
207
207
208
- def deprecate_arguments (
209
- kwarg_map : dict [str , str | None ],
210
- category : Type [Warning ] = DeprecationWarning ,
211
- * ,
212
- since : str | None = None ,
213
- ):
214
- """Deprecated. Instead, use `@deprecate_arg`.
215
-
216
- Args:
217
- kwarg_map: A dictionary of the old argument name to the new name.
218
- category: Usually either DeprecationWarning or PendingDeprecationWarning.
219
- since: The version the deprecation started at. Only Optional for backwards
220
- compatibility - this should always be set. If the deprecation is pending, set
221
- the version to when that started; but later, when switching from pending to
222
- deprecated, update `since` to the new version.
223
-
224
- Returns:
225
- Callable: The decorated callable.
226
- """
227
-
228
- def decorator (func ):
229
- func_name = func .__qualname__
230
- old_kwarg_to_msg = {}
231
- for old_arg , new_arg in kwarg_map .items ():
232
- msg_suffix = (
233
- "will in the future be removed." if new_arg is None else f"replaced with { new_arg } ."
234
- )
235
- old_kwarg_to_msg [old_arg ] = (
236
- f"{ func_name } keyword argument { old_arg } is deprecated and { msg_suffix } "
237
- )
238
-
239
- @functools .wraps (func )
240
- def wrapper (* args , ** kwargs ):
241
- for old , new in kwarg_map .items ():
242
- _maybe_warn_and_rename_kwarg (
243
- args ,
244
- kwargs ,
245
- func_name = func_name ,
246
- original_func_co_varnames = wrapper .__original_func_co_varnames ,
247
- old_arg_name = old ,
248
- new_alias = new ,
249
- warning_msg = old_kwarg_to_msg [old ],
250
- category = category ,
251
- predicate = None ,
252
- )
253
- return func (* args , ** kwargs )
254
-
255
- # When decorators get called repeatedly, `func` refers to the result of the prior
256
- # decorator, not the original underlying function. This trick allows us to record the
257
- # original function's variable names regardless of how many decorators are used.
258
- #
259
- # If it's the very first decorator call, we also check that *args and **kwargs are not used.
260
- if hasattr (func , "__original_func_co_varnames" ):
261
- wrapper .__original_func_co_varnames = func .__original_func_co_varnames
262
- else :
263
- wrapper .__original_func_co_varnames = func .__code__ .co_varnames
264
- param_kinds = {param .kind for param in inspect .signature (func ).parameters .values ()}
265
- if inspect .Parameter .VAR_POSITIONAL in param_kinds :
266
- raise ValueError (
267
- "@deprecate_arg cannot be used with functions that take variable *args. Use "
268
- "warnings.warn() directly instead."
269
- )
270
-
271
- for msg in old_kwarg_to_msg .values ():
272
- add_deprecation_to_docstring (
273
- wrapper , msg , since = since , pending = issubclass (category , PendingDeprecationWarning )
274
- )
275
- return wrapper
276
-
277
- return decorator
278
-
279
-
280
- def deprecate_function (
281
- msg : str ,
282
- stacklevel : int = 2 ,
283
- category : Type [Warning ] = DeprecationWarning ,
284
- * ,
285
- since : str | None = None ,
286
- ):
287
- """Deprecated. Instead, use `@deprecate_func`.
288
-
289
- Args:
290
- msg: Warning message to emit.
291
- stacklevel: The warning stacklevel to use, defaults to 2.
292
- category: Usually either DeprecationWarning or PendingDeprecationWarning.
293
- since: The version the deprecation started at. Only Optional for backwards
294
- compatibility - this should always be set. If the deprecation is pending, set
295
- the version to when that started; but later, when switching from pending to
296
- deprecated, update `since` to the new version.
297
-
298
- Returns:
299
- Callable: The decorated, deprecated callable.
300
- """
301
-
302
- def decorator (func ):
303
- @functools .wraps (func )
304
- def wrapper (* args , ** kwargs ):
305
- warnings .warn (msg , category = category , stacklevel = stacklevel )
306
- return func (* args , ** kwargs )
307
-
308
- add_deprecation_to_docstring (
309
- wrapper , msg , since = since , pending = issubclass (category , PendingDeprecationWarning )
310
- )
311
- return wrapper
312
-
313
- return decorator
314
-
315
-
316
208
def _maybe_warn_and_rename_kwarg (
317
209
args : tuple [Any , ...],
318
210
kwargs : dict [str , Any ],
0 commit comments