python / python/mypy

Feature request: option that prohibits any use of type:ignore, and other type-checking-suppression mechanisms

Open
#17,078 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature topic-type-ignore
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Feature

PEP 484 lists several ways to ignore type checking https://peps.python.org/pep-0484/#compatibility-with-other-uses-of-function-annotations:

  • # type: ignore comment
  • a @no_type_check decorator on a class or function
  • a custom class or function decorator marked with @no_type_check_decorator

I would like an option that disallows all of these methods, eg --disallow-type-ignores

Pitch

My basic idea here is that I want to actually enforce typing and have it completely statically verified, when possible. If that isn't happening, I'd like to know! And possibly refactor my code to remove the ignores. — I would like mypy to be able to tell me whether or not my types are completely automatically enforced, without any ignores, if I use the right flag. This seems like an ergonomic way to enable that. (There are probably other ways to cheat the python type checker that could also be ruled out, with other flags.)

While useful, these type-checker-ignore features get around static type safety without ensuring dynamic type correctness, which is not ideal. Sometimes you have to use them—you know how it is—but it's not ideal. That means, in my opinion, it would be great to have a option for disallowing their use, to ensure mandatory type-safety in codebases where these workarounds are not in fact needed.

I don't think it would make sense to turn this option on by default, nor in strict mode. The ecosystem of typing just isn't thorough and unimpingable enough, in my experience. It could maybe make sense to go in some hypothetical ultrastrict mode, but I don't think most strict mode users would benefit from this option being turned on.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the PEP 484 suppression mechanisms listed in the issue and trace where mypy handles command-line options and type-checking suppression. Define the option's scope and behavior for type: ignore, @no_type_check, and @no_type_check_decorator, then add coverage showing that each mechanism is rejected when the option is enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.