Skip to content

Commit 130b432

Browse files
committed
feat: add stacklevel kwarg to depecation utils
1 parent d49b015 commit 130b432

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

discord/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ def warn_deprecated(
296296
since: str | None = None,
297297
removed: str | None = None,
298298
reference: str | None = None,
299+
stacklevel: int = 3,
299300
) -> None:
300301
"""Warn about a deprecated function, with the ability to specify details about the deprecation. Emits a
301302
DeprecationWarning.
@@ -315,6 +316,8 @@ def warn_deprecated(
315316
reference: Optional[:class:`str`]
316317
A reference that explains the deprecation, typically a URL to a page such as a changelog entry or a GitHub
317318
issue/PR.
319+
stacklevel: :class:`int`
320+
The stacklevel kwarg passed to :func:`warnings.warn`. Defaults to 3.
318321
"""
319322
warnings.simplefilter("always", DeprecationWarning) # turn off filter
320323
message = f"{name} is deprecated"
@@ -328,7 +331,7 @@ def warn_deprecated(
328331
if reference:
329332
message += f" See {reference} for more information."
330333

331-
warnings.warn(message, stacklevel=3, category=DeprecationWarning)
334+
warnings.warn(message, stacklevel=stacklevel, category=DeprecationWarning)
332335
warnings.simplefilter("default", DeprecationWarning) # reset filter
333336

334337

@@ -337,6 +340,7 @@ def deprecated(
337340
since: str | None = None,
338341
removed: str | None = None,
339342
reference: str | None = None,
343+
stacklevel: int = 3,
340344
*,
341345
use_qualname: bool = True,
342346
) -> Callable[[Callable[[P], T]], Callable[[P], T]]:
@@ -356,6 +360,8 @@ def deprecated(
356360
reference: Optional[:class:`str`]
357361
A reference that explains the deprecation, typically a URL to a page such as a changelog entry or a GitHub
358362
issue/PR.
363+
stacklevel: :class:`int`
364+
The stacklevel kwarg passed to :func:`warnings.warn`. Defaults to 3.
359365
use_qualname: :class:`bool`
360366
Whether to use the qualified name of the function in the deprecation warning. If ``False``, the short name of
361367
the function will be used instead. For example, __qualname__ will display as ``Client.login`` while __name__

0 commit comments

Comments
 (0)