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

Take ClientT inside of the ErrorFunc #9975

Merged
merged 1 commit into from
Oct 14, 2024
Merged

Conversation

PythonCoderAS
Copy link
Contributor

Summary

Currently, using self.tree.error inside of a Bot or another subclass with proper type checking enabled via Pylance:

from discord.ext.commands import Bot
from discord import Interaction

class MyBot(Bot):
    def __init__(self, *a, **kw):
        super().__init__(*a, **kw)

        @self.tree.error
        async def tree_error(interaction: Interaction[MyBot], error: Exception):
            print("Error!")

Error:

Argument of type "(interaction: Interaction[MyBot], error: Exception) -> Coroutine[Any, Any, None]" cannot be assigned to parameter "coro" of type "ErrorFunc" in function "error"
  Type "(interaction: Interaction[MyBot], error: Exception) -> Coroutine[Any, Any, None]" is not assignable to type "ErrorFunc"
    Parameter 1: type "Interaction[Client]" is incompatible with type "Interaction[MyBot]"
      "Interaction[Client]" is not assignable to "Interaction[MyBot]"
        Type parameter "ClientT@Interaction" is covariant, but "Client" is not a subtype of "MyBot"
          "Client" is not assignable to "MyBot"Pylance[reportArgumentType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportArgumentType)

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

@Rapptz Rapptz merged commit 9da131e into Rapptz:master Oct 14, 2024
8 checks passed
@PythonCoderAS PythonCoderAS deleted the patch-3 branch October 15, 2024 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants