Skip to content

Add basic implementation for mypy: ignore comments - #22180

Open
ilevkivskyi wants to merge 2 commits into
python:masterfrom
ilevkivskyi:mypy-ignore
Open

ilevkivskyi wants to merge 2 commits into
python:masterfrom
ilevkivskyi:mypy-ignore

Conversation

@ilevkivskyi

Copy link
Copy Markdown
Member

Fixes #12358

Implementation is mostly straightforward, but there are few things:

  • This requires Straighten type comment parsing mypyc/ast_serialize#95, so tests will fail until we merge that.
  • We forgot to bump cache version to 6. This is trivial however, functions now have a flag indicating if they have a type comment.
  • I found a pretty bad bug in native parser: parse errors cannot be type-ignored even if they are non-blocking. Again, it is a one line change, so not making a separate PR for this.

Finally, there is one thing that bothers me a bit: we have few places where we mention words type: ignore in errors and notes. However, it would take a significant effort to reliably change them to mypy: ignore when needed. Essentially we would need to record provenance for each error code, and thread it through to many places (including to cache metas, for some technical reasons). So we have three options:

  1. Do nothing about it. mypy: ignore really means mypy-specific type ignore, so it is fine to use type: ignore in error notes, if we actually have mypy: ignore written in code.
  2. Actually implement all the work needed (not a fan of this option TBH).
  3. Change the wording in those few errors/notes so that it is more neutral: i.e. say Unused "ignore" comment instead of Unused "type: ignore" comment etc.

I am leaning towards option 3, but wanted to double-check before actually doing this.

cc @JukkaL

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

sockeye (https://github.com/awslabs/sockeye)
+ sockeye/layers.py:642: error: Unused "type: ignore" comment  [unused-ignore]

scipy-stubs (https://github.com/scipy/scipy-stubs)
+ tests/misc/test_submodules_empty.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support mypy: ignore inline comments to suppress mypy errors

1 participant