Skip to content

Enforce error codes on type: ignores #10718

@TylerYep

Description

@TylerYep

Feature

As far as I know, there's no way to enforce an error code is added to the end of a type ignore. Since error codes can narrow the type errors ignored on a specific line, it would be useful to ensure all # type: ignores in a codebase included an error code, to avoid silencing additional errors or disabling otherwise valid typechecking on a line.

The feature could be a config option --enforce-error-codes that verifies all type: ignores specify an error code.

x: int = None  # type: ignore                <- mypy complains
x: int = None  # type: ignore[assignment]    <- good!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions