Code is properly annotated so pyright and mypy doesn't throw any error.
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]
Changing List[BaseHandler[Any, CCT, Any] to Sequence[BaseHandler[Any, CCT, Any] seems to fix the issue.
Steps to Reproduce
pyright main.py && mypy main.pyExpected 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.
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: