Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove module-level deprecation warn #2450

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2421](https://github.com/Pycord-Development/pycord/pull/2421))
- Added `member` data to the `raw_reaction_remove` event.
([#2412](https://github.com/Pycord-Development/pycord/pull/2412))
- Added `stacklevel` param to `utils.warn_deprecated` and `utils.deprecated`.
([#2450](https://github.com/Pycord-Development/pycord/pull/2450))

### Fixed

Expand Down
32 changes: 22 additions & 10 deletions discord/ext/bridge/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,28 @@ class BridgeExtCommand(Command):
def __init__(self, func, **kwargs):
super().__init__(func, **kwargs)

# TODO: v2.7: Remove backwards support for Option in bridge commands.
for name, option in self.params.items():
if isinstance(option.annotation, Option) and not isinstance(
option.annotation, BridgeOption
):
# Warn not to do this
warn_deprecated(
"Using Option for bridge commands",
"BridgeOption",
"2.5",
"2.7",
reference="https://github.com/Pycord-Development/pycord/pull/2417",
stacklevel=6,
)
# Override the convert method of the parameter's annotated Option.
# We can use the convert method from BridgeOption, and bind "self"
# using a manual invocation of the descriptor protocol.
# Definitely not a good approach, but gets the job done until removal.
self.params[name].annotation.convert = BridgeOption.convert.__get__(
self.params[name].annotation
)

async def dispatch_error(self, ctx: BridgeExtContext, error: Exception) -> None:
await super().dispatch_error(ctx, error)
ctx.bot.dispatch("bridge_command_error", ctx, error)
Expand Down Expand Up @@ -653,13 +675,3 @@ def decorator(func):
return func

return decorator


discord.commands.options.Option = BridgeOption
discord.Option = BridgeOption
warn_deprecated(
"Option",
"BridgeOption",
"2.5",
reference="https://github.com/Pycord-Development/pycord/pull/2417",
)
8 changes: 7 additions & 1 deletion discord/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ def warn_deprecated(
since: str | None = None,
removed: str | None = None,
reference: str | None = None,
stacklevel: int = 3,
) -> None:
"""Warn about a deprecated function, with the ability to specify details about the deprecation. Emits a
DeprecationWarning.
Expand All @@ -315,6 +316,8 @@ def warn_deprecated(
reference: Optional[:class:`str`]
A reference that explains the deprecation, typically a URL to a page such as a changelog entry or a GitHub
issue/PR.
stacklevel: :class:`int`
The stacklevel kwarg passed to :func:`warnings.warn`. Defaults to 3.
"""
warnings.simplefilter("always", DeprecationWarning) # turn off filter
message = f"{name} is deprecated"
Expand All @@ -328,7 +331,7 @@ def warn_deprecated(
if reference:
message += f" See {reference} for more information."

warnings.warn(message, stacklevel=3, category=DeprecationWarning)
warnings.warn(message, stacklevel=stacklevel, category=DeprecationWarning)
warnings.simplefilter("default", DeprecationWarning) # reset filter


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