Missing type hints in SimpleCustomFilter
vehlwn opened this issue · comments
- pytelegrambotapi 4.17.0
- Arch Linux
- 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...