Skip to content

[mypy]: ignore at file begin does not accept error code, silently ignores all errors instead #2410

@DerBiasto

Description

@DerBiasto

All the example files have a # type: ignore[union-attr] comment right at the start.

However mypy currently (0.812) does not support file-global ignoring of specific error codes 1. Therefore the mentioned ignore line simply silences each and every error in the file instead of only those with the specified error code.

For example in examples/inlinebot there are actually 8 mypy errors if you remove the ignore at the start, only 4 of which are [union-attr], the others are all [type-arg].

In particular one complaint (and mypy even suggests the correct fix for this) is that the call signature for InlineQuery.answer takes List[InlineQueryResult], but gets List[InlineQueryResultArticle], which doesn't work because List is invariant, so Sequence should be used instead, because it is covariant. Getting this error in my personal project is what prompted me to look into this.

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