python / python/mypy

Support 'on'/'off' for type ignores

Open
#9,483 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Sometimes it's impossible to put # type: ignore on the offending line - e.g. because it's a multiline string, and there's nowhere you can put the comment outside the string that mypy will recognise. Or more generally, there might be a whole block of code for which mypy has a bunch of spurious complaints, so putting in dozens of # type: ignores is a bit noisy.

The only other option today is to have mypy ignore the entire file, but that has nasty ramifications - beyond just killing type checking for what might be 99% checkable, it also makes any imports of that file invalid, and so you have to spread ignore directives out like a messy spiderweb.

Thus, it'd be great if one could do e.g. # type: ignore on and # type: ignore off, so that the scope could be controlled precisely.

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

The issue names no files, tests, or entry points. Start by tracing how mypy currently parses and applies # type: ignore directives, then determine how on and off should scope diagnostics across multiline strings and code blocks. Done means scoped ignores work without disabling checking for the rest of the file or invalidating imports.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
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.