eternnoir / pyTelegramBotAPI

Python Telegram bot api.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing type hints in SimpleCustomFilter

vehlwn opened this issue · comments

  1. pytelegrambotapi 4.17.0
  2. Arch Linux
  3. Python 3.12.3

The issue related to my previous question. On the following code pyright terminates with error due to missing type hints:

class MatchBotUsernameFilter(telebot.asyncio_filters.SimpleCustomFilter):
    key = "match_bot_username"

    def __init__(self, bot_name: str) -> None:
        super().__init__()
        self.bot_name = bot_name

    async def check(self, message: telebot.types.Message) -> bool:
        text = message.text or ""
        words = text.split(maxsplit=1)
        full_command = words[0].split("@")
        if len(full_command) >= 2:
            bot_username = full_command[1]
            return bot_username == self.bot_name
        return True
error: Method "check" overrides class "SimpleCustomFilter" in an incompatible manner
    Return type mismatch: base method returns type "Coroutine[Any, Any, None]", override returns type "Coroutine[Any, Any, bool]"
      "Coroutine[Any, Any, bool]" is incompatible with "Coroutine[Any, Any, None]"
        Type parameter "_ReturnT_co@Coroutine" is covariant, but "bool" is not a subtype of "None"
          "bool" is incompatible with "None" (reportIncompatibleMethodOverride)

Documentaion says:

Simple Custom Filter base class. Create child class with check() method. Accepts only message, returns bool value, that is compared with given in handler.

But there are no type hints to indicate bool return type. This can be easily fixed here.

Just make a PR...

Here it is #2251