Skip to content

[BUG] Incorrect type hinting for Handlers #2242

@revolter

Description

@revolter

Steps to reproduce

This line:

``def callback(update: Update, context: CallbackContext)``

contradicts with this line:

HandlerArg = Union[str, 'Update']

And I think that the update parameter can actually never be str, right?

Expected behaviour

No mypy issue for

dispatcher.add_handler(telegram.ext.CommandHandler('start', start_command_handler))

and

def start_command_handler(update: telegram.Update, context: telegram.ext.CallbackContext) -> None:

Actual behaviour

Argument 2 to "CommandHandler" has incompatible type "Callable[[Update, CallbackContext], None]"; expected "Callable[[Union[str, Update], CallbackContext], None]" 

Configuration

Operating System:

macOS 10.15.7 (19H15)

Version of Python, python-telegram-bot & dependencies:

$ python -m telegram

python-telegram-bot 13.1
certifi 2020.11.08
Python 3.9.0 (default, Nov 21 2020, 14:01:50) [Clang 12.0.0 (clang-1200.0.32.27)]

Logs

Insert logs here (if necessary)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions