Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BUG] Incorrect type hinting for Application.create_task #3540

Closed
@sam-mosleh

Description

@sam-mosleh

Steps to Reproduce

In the wiki you have provided an example for Avoiding flood limits :

async def broadcast(update: Update, context: ContextTypes.DEFAULT_TYPE):
    await update.message.reply_text(text="Starting the broadcast...")
    context.application.create_task(
        asyncio.gather(
            *(
                context.bot.send_message(
                    chat_id=user_id, text="Hello World!", rate_limit_args={'priority': -1}
                )
                for user_id in user_ids
            )
        )
    )

which has a typing issue because asyncio.gather returns a asyncio.Future and Application.create_task expects an asyncio.Coroutine

Expected behaviour

Application.create_task should also expect a Future besides Coroutine.

Actual behaviour

def create_task(self, coroutine: Coroutine, update: object = None) -> asyncio.Task:

Operating System

Manjaro Linux 22.0.0

Version of Python, python-telegram-bot & dependencies

python-telegram-bot 20.0
Bot API 6.4
Python 3.10.6 (main, Aug 23 2022, 08:36:38) [GCC 10.2.1 20210110]

Relevant log output

No response

Additional Context

No response

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