Skip to content

Commit 162d155

Browse files
committed
♻️ move deprecation utilities to private utils and update references
1 parent 24fea39 commit 162d155

File tree

11 files changed

+122
-116
lines changed

11 files changed

+122
-116
lines changed

CHANGELOG-V3.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ release.
1717
- `utils.sleep_until`
1818
- `utils.resolve_invite`
1919
- `utils.parse_time`
20-
- `utils.time_snowflake` use `utils.generate_snowflake` instead
20+
- `utils.time_snowflake` use `utils.generate_snowflake` instead
21+
- `utils.warn_deprecated`
22+
- `utils.deprecated`

discord/__version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
from typing import Literal, NamedTuple
3737

38-
from .utils import deprecated
38+
from .utils.private import deprecated
3939
from ._version import __version__, __version_tuple__
4040

4141

discord/abc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
runtime_checkable,
4242
)
4343

44+
from .utils.private import warn_deprecated
4445
from . import utils
4546
from .context_managers import Typing
4647
from .enums import ChannelType
@@ -1529,7 +1530,7 @@ async def send(
15291530
from .message import MessageReference
15301531

15311532
if not isinstance(reference, MessageReference):
1532-
utils.warn_deprecated(
1533+
warn_deprecated(
15331534
f"Passing {type(reference).__name__} to reference",
15341535
"MessageReference",
15351536
"2.7",

discord/appinfo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
from typing import TYPE_CHECKING
2929

30+
from .utils.private import warn_deprecated
3031
from .utils.private import get_as_snowflake
3132
from . import utils
3233
from .asset import Asset
@@ -262,7 +263,7 @@ def summary(self) -> str | None:
262263
.. versionadded:: 1.3
263264
.. deprecated:: 2.7
264265
"""
265-
utils.warn_deprecated(
266+
warn_deprecated(
266267
"summary",
267268
"description",
268269
reference="https://discord.com/developers/docs/resources/application#application-object-application-structure",

discord/commands/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868
from ..role import Role
6969
from ..threads import Thread
7070
from ..user import User
71-
from ..utils import MISSING, async_all, find, maybe_coroutine, utcnow, warn_deprecated
71+
from ..utils import MISSING, async_all, find, maybe_coroutine, utcnow
72+
from ..utils.private import warn_deprecated
7273
from .context import ApplicationContext, AutocompleteContext
7374
from .options import Option, OptionChoice
7475

discord/ext/bridge/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
SlashCommandOptionType,
4141
)
4242

43-
from ...utils import MISSING, find, get, warn_deprecated
43+
from ...utils import MISSING, find, get
44+
from ...utils.private import warn_deprecated
4445
from ..commands import (
4546
BadArgument,
4647
)

discord/http.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
)
4848
from .file import VoiceMessage
4949
from .gateway import DiscordClientWebSocketResponse
50-
from .utils import MISSING, warn_deprecated
50+
from .utils import MISSING
51+
from .utils.private import warn_deprecated
5152

5253
_log = logging.getLogger(__name__)
5354

discord/interactions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def is_component(self) -> bool:
292292
return self.type == InteractionType.component
293293

294294
@utils.cached_slot_property("_cs_channel")
295-
@utils.deprecated("Interaction.channel", "2.7", stacklevel=4)
295+
@discord.utils.private.deprecated("Interaction.channel", "2.7", stacklevel=4)
296296
def cached_channel(self) -> InteractionChannel | None:
297297
"""The cached channel from which the interaction was sent.
298298
DM channels are not resolved. These are :class:`PartialMessageable` instead.
@@ -428,7 +428,7 @@ async def original_response(self) -> InteractionMessage:
428428
self._original_response = message
429429
return message
430430

431-
@utils.deprecated("Interaction.original_response", "2.2")
431+
@discord.utils.private.deprecated("Interaction.original_response", "2.2")
432432
async def original_message(self):
433433
"""An alias for :meth:`original_response`.
434434
@@ -555,7 +555,7 @@ async def edit_original_response(
555555

556556
return message
557557

558-
@utils.deprecated("Interaction.edit_original_response", "2.2")
558+
@discord.utils.private.deprecated("Interaction.edit_original_response", "2.2")
559559
async def edit_original_message(self, **kwargs):
560560
"""An alias for :meth:`edit_original_response`.
561561
@@ -613,7 +613,7 @@ async def delete_original_response(self, *, delay: float | None = None) -> None:
613613
else:
614614
await func
615615

616-
@utils.deprecated("Interaction.delete_original_response", "2.2")
616+
@discord.utils.private.deprecated("Interaction.delete_original_response", "2.2")
617617
async def delete_original_message(self, **kwargs):
618618
"""An alias for :meth:`delete_original_response`.
619619
@@ -1238,7 +1238,7 @@ async def send_modal(self, modal: Modal) -> Interaction:
12381238
self._parent._state.store_modal(modal, self._parent.user.id)
12391239
return self._parent
12401240

1241-
@utils.deprecated("a button with type ButtonType.premium", "2.6")
1241+
@discord.utils.private.deprecated("a button with type ButtonType.premium", "2.6")
12421242
async def premium_required(self) -> Interaction:
12431243
"""|coro|
12441244

discord/message.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
)
4242
from urllib.parse import parse_qs, urlparse
4343

44-
from .utils.private import get_as_snowflake, parse_time
44+
from .utils.private import get_as_snowflake, parse_time, warn_deprecated
4545
from . import utils
4646
from .channel import PartialMessageable
4747
from .components import _component_factory
@@ -1245,7 +1245,7 @@ def _rebind_cached_references(self, new_guild: Guild, new_channel: TextChannel |
12451245

12461246
@property
12471247
def interaction(self) -> MessageInteraction | None:
1248-
utils.warn_deprecated(
1248+
warn_deprecated(
12491249
"interaction",
12501250
"interaction_metadata",
12511251
"2.6",
@@ -1255,7 +1255,7 @@ def interaction(self) -> MessageInteraction | None:
12551255

12561256
@interaction.setter
12571257
def interaction(self, value: MessageInteraction | None) -> None:
1258-
utils.warn_deprecated(
1258+
warn_deprecated(
12591259
"interaction",
12601260
"interaction_metadata",
12611261
"2.6",

discord/utils/__init__.py

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@
2929
import asyncio
3030
import collections.abc
3131
import datetime
32-
import functools
3332
import json
3433
import re
3534
import sys
3635
import types
37-
import warnings
3836
from bisect import bisect_left
3937
from enum import Enum, auto
4038
from inspect import isawaitable as _isawaitable
@@ -73,8 +71,6 @@
7371

7472

7573
__all__ = (
76-
"warn_deprecated",
77-
"deprecated",
7874
"oauth_url",
7975
"snowflake_time",
8076
"find",
@@ -240,102 +236,6 @@ def decorator(overridden: T) -> T:
240236
return decorator
241237

242238

243-
def warn_deprecated(
244-
name: str,
245-
instead: str | None = None,
246-
since: str | None = None,
247-
removed: str | None = None,
248-
reference: str | None = None,
249-
stacklevel: int = 3,
250-
) -> None:
251-
"""Warn about a deprecated function, with the ability to specify details about the deprecation. Emits a
252-
DeprecationWarning.
253-
254-
Parameters
255-
----------
256-
name: str
257-
The name of the deprecated function.
258-
instead: Optional[:class:`str`]
259-
A recommended alternative to the function.
260-
since: Optional[:class:`str`]
261-
The version in which the function was deprecated. This should be in the format ``major.minor(.patch)``, where
262-
the patch version is optional.
263-
removed: Optional[:class:`str`]
264-
The version in which the function is planned to be removed. This should be in the format
265-
``major.minor(.patch)``, where the patch version is optional.
266-
reference: Optional[:class:`str`]
267-
A reference that explains the deprecation, typically a URL to a page such as a changelog entry or a GitHub
268-
issue/PR.
269-
stacklevel: :class:`int`
270-
The stacklevel kwarg passed to :func:`warnings.warn`. Defaults to 3.
271-
"""
272-
warnings.simplefilter("always", DeprecationWarning) # turn off filter
273-
message = f"{name} is deprecated"
274-
if since:
275-
message += f" since version {since}"
276-
if removed:
277-
message += f" and will be removed in version {removed}"
278-
if instead:
279-
message += f", consider using {instead} instead"
280-
message += "."
281-
if reference:
282-
message += f" See {reference} for more information."
283-
284-
warnings.warn(message, stacklevel=stacklevel, category=DeprecationWarning)
285-
warnings.simplefilter("default", DeprecationWarning) # reset filter
286-
287-
288-
def deprecated(
289-
instead: str | None = None,
290-
since: str | None = None,
291-
removed: str | None = None,
292-
reference: str | None = None,
293-
stacklevel: int = 3,
294-
*,
295-
use_qualname: bool = True,
296-
) -> Callable[[Callable[[P], T]], Callable[[P], T]]:
297-
"""A decorator implementation of :func:`warn_deprecated`. This will automatically call :func:`warn_deprecated` when
298-
the decorated function is called.
299-
300-
Parameters
301-
----------
302-
instead: Optional[:class:`str`]
303-
A recommended alternative to the function.
304-
since: Optional[:class:`str`]
305-
The version in which the function was deprecated. This should be in the format ``major.minor(.patch)``, where
306-
the patch version is optional.
307-
removed: Optional[:class:`str`]
308-
The version in which the function is planned to be removed. This should be in the format
309-
``major.minor(.patch)``, where the patch version is optional.
310-
reference: Optional[:class:`str`]
311-
A reference that explains the deprecation, typically a URL to a page such as a changelog entry or a GitHub
312-
issue/PR.
313-
stacklevel: :class:`int`
314-
The stacklevel kwarg passed to :func:`warnings.warn`. Defaults to 3.
315-
use_qualname: :class:`bool`
316-
Whether to use the qualified name of the function in the deprecation warning. If ``False``, the short name of
317-
the function will be used instead. For example, __qualname__ will display as ``Client.login`` while __name__
318-
will display as ``login``. Defaults to ``True``.
319-
"""
320-
321-
def actual_decorator(func: Callable[[P], T]) -> Callable[[P], T]:
322-
@functools.wraps(func)
323-
def decorated(*args: P.args, **kwargs: P.kwargs) -> T:
324-
warn_deprecated(
325-
name=func.__qualname__ if use_qualname else func.__name__,
326-
instead=instead,
327-
since=since,
328-
removed=removed,
329-
reference=reference,
330-
stacklevel=stacklevel,
331-
)
332-
return func(*args, **kwargs)
333-
334-
return decorated
335-
336-
return actual_decorator
337-
338-
339239
def oauth_url(
340240
client_id: int | str,
341241
*,

0 commit comments

Comments
 (0)