PythonistaGuild / TwitchIO

An Async Bot/API wrapper for Twitch made in Python.
https://twitchio.dev
MIT License
785 stars 163 forks source link

fix for `Argument of type "type[Command]" cannot be assigned to parameter "cls" of type "C@command" in function "command"` #431

Closed violet4 closed 11 months ago

violet4 commented 11 months ago

Pull request summary

previously the typing of function twitchio.ext.command.core.command declared an argument cls: C = Command, but that was throwing a linting error (vscode pylance in my case) in any code that tried to create a command. it has been changed to cls: type[C] = Command.

demo code that showed the error before, and fixed after the change:

from twitchio.ext import commands

class MyBot(commands.Bot):

    # Argument of type "type[Command]" cannot be assigned to parameter "cls" of type "C@command" in function "command"
    # Type "type[Command]" cannot be assigned to type "Command"
    #     "type[type]" is incompatible with "type[Command]"PylancereportGeneralTypeIssues

    @commands.command(name="hello", aliases=['hi'])
    async def hello(self, ctx: commands.Context):
        await ctx.send(f'Hello {ctx.author.name}!')

Checklist

chillymosh commented 11 months ago

Thanks