Skip to content

Commit 32029fe

Browse files
authored
Merge 5de15f2 into 6c990b9
2 parents 6c990b9 + 5de15f2 commit 32029fe

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

discord/ext/bridge/core.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,28 @@ class BridgeExtCommand(Command):
9696
def __init__(self, func, **kwargs):
9797
super().__init__(func, **kwargs)
9898

99+
# TODO: v2.7: Remove backwards support for Option in bridge commands.
100+
for name, option in self.params.items():
101+
if isinstance(option.annotation, Option) and not isinstance(
102+
option.annotation, BridgeOption
103+
):
104+
# Warn not to do this
105+
warn_deprecated(
106+
"Using Option for bridge commands",
107+
"BridgeOption",
108+
"2.5",
109+
"2.7",
110+
reference="https://github.com/Pycord-Development/pycord/pull/2417",
111+
stacklevel=6,
112+
)
113+
# Override the convert method of the parameter's annotated Option.
114+
# We can use the convert method from BridgeOption, and bind "self"
115+
# using a manual invocation of the descriptor protocol.
116+
# Definitely not a good approach, but gets the job done until removal.
117+
self.params[name].annotation.convert = BridgeOption.convert.__get__(
118+
self.params[name].annotation
119+
)
120+
99121
async def dispatch_error(self, ctx: BridgeExtContext, error: Exception) -> None:
100122
await super().dispatch_error(ctx, error)
101123
ctx.bot.dispatch("bridge_command_error", ctx, error)
@@ -653,13 +675,3 @@ def decorator(func):
653675
return func
654676

655677
return decorator
656-
657-
658-
discord.commands.options.Option = BridgeOption
659-
discord.Option = BridgeOption
660-
warn_deprecated(
661-
"Option",
662-
"BridgeOption",
663-
"2.5",
664-
reference="https://github.com/Pycord-Development/pycord/pull/2417",
665-
)

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)