@@ -296,6 +296,7 @@ def warn_deprecated(
296
296
since : str | None = None ,
297
297
removed : str | None = None ,
298
298
reference : str | None = None ,
299
+ stacklevel : int = 3 ,
299
300
) -> None :
300
301
"""Warn about a deprecated function, with the ability to specify details about the deprecation. Emits a
301
302
DeprecationWarning.
@@ -315,6 +316,8 @@ def warn_deprecated(
315
316
reference: Optional[:class:`str`]
316
317
A reference that explains the deprecation, typically a URL to a page such as a changelog entry or a GitHub
317
318
issue/PR.
319
+ stacklevel: :class:`int`
320
+ The stacklevel kwarg passed to :func:`warnings.warn`. Defaults to 3.
318
321
"""
319
322
warnings .simplefilter ("always" , DeprecationWarning ) # turn off filter
320
323
message = f"{ name } is deprecated"
@@ -328,7 +331,7 @@ def warn_deprecated(
328
331
if reference :
329
332
message += f" See { reference } for more information."
330
333
331
- warnings .warn (message , stacklevel = 3 , category = DeprecationWarning )
334
+ warnings .warn (message , stacklevel = stacklevel , category = DeprecationWarning )
332
335
warnings .simplefilter ("default" , DeprecationWarning ) # reset filter
333
336
334
337
@@ -337,6 +340,7 @@ def deprecated(
337
340
since : str | None = None ,
338
341
removed : str | None = None ,
339
342
reference : str | None = None ,
343
+ stacklevel : int = 3 ,
340
344
* ,
341
345
use_qualname : bool = True ,
342
346
) -> Callable [[Callable [[P ], T ]], Callable [[P ], T ]]:
@@ -356,6 +360,8 @@ def deprecated(
356
360
reference: Optional[:class:`str`]
357
361
A reference that explains the deprecation, typically a URL to a page such as a changelog entry or a GitHub
358
362
issue/PR.
363
+ stacklevel: :class:`int`
364
+ The stacklevel kwarg passed to :func:`warnings.warn`. Defaults to 3.
359
365
use_qualname: :class:`bool`
360
366
Whether to use the qualified name of the function in the deprecation warning. If ``False``, the short name of
361
367
the function will be used instead. For example, __qualname__ will display as ``Client.login`` while __name__
0 commit comments