Skip to content

Commit d2e99a7

Browse files
Paillat-devLulalabyDorukyum
authored
chore: 🗑️ Deprecate deprecated (#3118)
* 🗑️ Deprecate `deprecated` * Update discord/utils.py Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Signed-off-by: Paillat <jeremiecotti@ik.me> * Update discord/utils.py Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Signed-off-by: Lala Sabathil <aiko@aitsys.dev> --------- Signed-off-by: Paillat <jeremiecotti@ik.me> Signed-off-by: Lala Sabathil <aiko@aitsys.dev> Co-authored-by: Lala Sabathil <lala@pycord.dev> Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
1 parent c7a168c commit d2e99a7

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

discord/utils.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
overload,
6565
)
6666

67+
from typing_extensions import deprecated as ext_deprecated
68+
6769
if TYPE_CHECKING:
6870
from discord import (
6971
Client,
@@ -94,6 +96,7 @@
9496
__all__ = (
9597
"parse_time",
9698
"warn_deprecated",
99+
"deprecated",
97100
"oauth_url",
98101
"snowflake_time",
99102
"time_snowflake",
@@ -344,6 +347,63 @@ def warn_deprecated(
344347
warnings.warn(message, stacklevel=stacklevel, category=DeprecationWarning)
345348

346349

350+
@ext_deprecated(
351+
"deprecated is deprecated since version 2.8, consider using warnings.deprecated instead."
352+
)
353+
def deprecated(
354+
instead: str | None = None,
355+
since: str | None = None,
356+
removed: str | None = None,
357+
reference: str | None = None,
358+
stacklevel: int = 3,
359+
*,
360+
use_qualname: bool = True,
361+
) -> Callable[[Callable[[P], T]], Callable[[P], T]]:
362+
"""A decorator implementation of :func:`warn_deprecated`. This will automatically call :func:`warn_deprecated` when
363+
the decorated function is called.
364+
365+
.. deprecated:: 2.8
366+
Deprecated in favor of :func:`warnings.deprecated`.
367+
368+
Parameters
369+
----------
370+
instead: Optional[:class:`str`]
371+
A recommended alternative to the function.
372+
since: Optional[:class:`str`]
373+
The version in which the function was deprecated. This should be in the format ``major.minor(.patch)``, where
374+
the patch version is optional.
375+
removed: Optional[:class:`str`]
376+
The version in which the function is planned to be removed. This should be in the format
377+
``major.minor(.patch)``, where the patch version is optional.
378+
reference: Optional[:class:`str`]
379+
A reference that explains the deprecation, typically a URL to a page such as a changelog entry or a GitHub
380+
issue/PR.
381+
stacklevel: :class:`int`
382+
The stacklevel kwarg passed to :func:`warnings.warn`. Defaults to 3.
383+
use_qualname: :class:`bool`
384+
Whether to use the qualified name of the function in the deprecation warning. If ``False``, the short name of
385+
the function will be used instead. For example, __qualname__ will display as ``Client.login`` while __name__
386+
will display as ``login``. Defaults to ``True``.
387+
"""
388+
389+
def actual_decorator(func: Callable[[P], T]) -> Callable[[P], T]:
390+
@functools.wraps(func)
391+
def decorated(*args: P.args, **kwargs: P.kwargs) -> T:
392+
warn_deprecated(
393+
name=func.__qualname__ if use_qualname else func.__name__,
394+
instead=instead,
395+
since=since,
396+
removed=removed,
397+
reference=reference,
398+
stacklevel=stacklevel,
399+
)
400+
return func(*args, **kwargs)
401+
402+
return decorated
403+
404+
return actual_decorator
405+
406+
347407
def oauth_url(
348408
client_id: int | str,
349409
*,

0 commit comments

Comments
 (0)