Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
from telegram import Update from telegram.ext import ( ApplicationBuilder, CommandHandler, ContextTypes, MessageHandler, filters, ) # pyright: strict async def hello(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: if update.message and update.effective_user: await update.message.reply_text(f"Hello {update.effective_user.first_name}") async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: if update.message and update.message.text: await update.message.reply_text(update.message.text) async def hi(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: if update.message: await update.message.reply_text("Hi") async def welcome(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: if update.message: await update.message.reply_text("Welcome") mixed_handlers = [ CommandHandler("hello", hello), MessageHandler(filters.TEXT & ~filters.COMMAND, echo), ] command_handlers = [ CommandHandler("hi", hi), CommandHandler("welcome", welcome), ] app = ApplicationBuilder().token("YOUR TOKEN HERE").build() app.add_handlers(mixed_handlers) app.add_handlers(command_handlers) app.run_polling()
pyright main.py && mypy main.py
Code is properly annotated so pyright and mypy doesn't throw any error.
Both mypy and pyright in strict mode will complain about invariance of
python-telegram-bot/telegram/ext/_application.py
Line 1423 in 0685463
Errors:
1. Argument 1 to "add_handlers" of "Application" has incompatible type "list[CommandHandler[CallbackContext[ExtBot[None], dict[Any, Any], dict[Any, Any], dict[Any, Any]], None]]"; expected "list[BaseHandler[Any, CallbackContext[ExtBot[None], dict[Any, Any], dict[Any, Any], dict[Any, Any]], Any]] | tuple[BaseHandler[Any, CallbackContext[ExtBot[None], dict[Any, Any], dict[Any, Any], dict[Any, Any]], Any]] | dict[int, list[BaseHandler[Any, CallbackContext[ExtBot[None], dict[Any, Any], dict[Any, Any], dict[Any, Any]], Any]] | tuple[BaseHandler[Any, CallbackContext[ExtBot[None], dict[Any, Any], dict[Any, Any], dict[Any, Any]], Any]]]" [arg-type] 2. "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance 3. Consider using "Sequence" instead, which is covariant 4. Argument 1 to "add_handlers" of "Application" has incompatible type "list[CommandHandler[CallbackContext[ExtBot[None], dict[Any, Any], dict[Any, Any], dict[Any, Any]], None]]"; expected "list[BaseHandler[Any, CallbackContext[ExtBot[None], dict[Any, Any], dict[Any, Any], dict[Any, Any]], Any]] | tuple[BaseHandler[Any, CallbackContext[ExtBot[None], dict[Any, Any], dict[Any, Any], dict[Any, Any]], Any]] | dict[int, list[BaseHandler[Any, CallbackContext[ExtBot[None], dict[Any, Any], dict[Any, Any], dict[Any, Any]], Any]] | tuple[BaseHandler[Any, CallbackContext[ExtBot[None], dict[Any, Any], dict[Any, Any], dict[Any, Any]], Any]]]" [arg-type] 5. Argument of type "list[CommandHandler[DEFAULT_TYPE, None]]" cannot be assigned to parameter "handlers" of type "List[BaseHandler[Any, DEFAULT_TYPE, Any]] | Tuple[BaseHandler[Any, DEFAULT_TYPE, Any]] | Dict[int, List[BaseHandler[Any, DEFAULT_TYPE, Any]] | Tuple[BaseHandler[Any, DEFAULT_TYPE, Any]]]" in function "add_handlers" Type "list[CommandHandler[DEFAULT_TYPE, None]]" is not assignable to type "List[BaseHandler[Any, DEFAULT_TYPE, Any]] | Tuple[BaseHandler[Any, DEFAULT_TYPE, Any]] | Dict[int, List[BaseHandler[Any, DEFAULT_TYPE, Any]] | Tuple[BaseHandler[Any, DEFAULT_TYPE, Any]]]" "list[CommandHandler[DEFAULT_TYPE, None]]" is not assignable to "List[BaseHandler[Any, DEFAULT_TYPE, Any]]" Type parameter "_T@list" is invariant, but "CommandHandler[DEFAULT_TYPE, None]" is not the same as "BaseHandler[Any, DEFAULT_TYPE, Any]" Consider switching from "list" to "Sequence" which is covariant "list[CommandHandler[DEFAULT_TYPE, None]]" is not assignable to "Tuple[BaseHandler[Any, DEFAULT_TYPE, Any]]" "list[CommandHandler[DEFAULT_TYPE, None]]" is not assignable to "Dict[int, List[BaseHandler[Any, DEFAULT_TYPE, Any]] | Tuple[BaseHandler[Any, DEFAULT_TYPE, Any]]]" [reportArgumentType]
Arch Linux
python 3.12.7
python-telegram-bot 21.6
mypy 1.12.1
pyright 1.1.385
No response
Changing List[BaseHandler[Any, CCT, Any] to Sequence[BaseHandler[Any, CCT, Any] seems to fix the issue.
def add_handlers( self, handlers: Union[ - Union[List[BaseHandler[Any, CCT, Any]], Tuple[BaseHandler[Any, CCT, Any]]], + Sequence[BaseHandler[Any, CCT, Any]], Dict[int, Union[List[BaseHandler[Any, CCT, Any]], Tuple[BaseHandler[Any, CCT, Any]]]], ], group: Union[int, DefaultValue[int]] = _DEFAULT_0, ) -> None:
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Steps to Reproduce
pyright main.py && mypy main.py
Expected behaviour
Code is properly annotated so pyright and mypy doesn't throw any error.
Actual behaviour
Both mypy and pyright in strict mode will complain about invariance of
python-telegram-bot/telegram/ext/_application.py
Line 1423 in 0685463
Errors:
Operating System
Arch Linux
Version of Python, python-telegram-bot & dependencies
python 3.12.7
python-telegram-bot 21.6
mypy 1.12.1
pyright 1.1.385
Relevant log output
No response
Additional Context
Changing List[BaseHandler[Any, CCT, Any] to Sequence[BaseHandler[Any, CCT, Any] seems to fix the issue.
The text was updated successfully, but these errors were encountered: