Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Consider a pretty standard command callback function:

async def command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
	await update.message.reply_text("hello world")

mypy will complain about this as message can vary depending on different calling contexts:

error: Item "None" of "Message | None" has no attribute "reply_text" [union-attr]

To keep mypy happy I've taken to using this pattern in all my callbacks:

async def command(update: Update, context: ContextTypes.DEFAULT_TYPE)) -> None:
	if update.message:
		await update.message.reply_text("hello world")

But its kind of annoying repeating this everywhere, and moreoever, none of the code examples seem bother with this. I know mypy isn't the be-all-end-all, but I'm curious about this discrepancy.

You must be logged in to vote

Replies: 1 comment

Comment options

Hi. please have a look at #3332

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
⁉️
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.