Skip to content

Fix bug with dmypy not respecting @no_type_check after change in dependency#21626

Open
thomasbbrunner wants to merge 1 commit into
python:masterfrom
thomasbbrunner:tbrunner/fix-dmypy-no-type-check
Open

Fix bug with dmypy not respecting @no_type_check after change in dependency#21626
thomasbbrunner wants to merge 1 commit into
python:masterfrom
thomasbbrunner:tbrunner/fix-dmypy-no-type-check

Conversation

@thomasbbrunner

Copy link
Copy Markdown

Currently, in daemon mode, the body of a @no_type_check function is type-checked anyway when the function is reprocessed because a type-check-dependency changed. This is even the case if the @no_type_check function isn't changed at all.

This leads to false positives, where mypy flags typing issues in a function that is not supposed to be type checked.

Other similar typing decorators are already correctly handled in the code. In this PR, I'm proposing to do the same for typing.no_type_check.

Moreover, this adds a fine-grained regression test.

Reproduction

To reproduce the bug described above:

  1. Create two local files:
# a.py
from typing import no_type_check
from b import SCALE

  @no_type_check
  def func() -> None:
      factor: int = SCALE
      bad: int = "definitely not an int"
# b.py
SCALE: int = 3
  1. Run the daemon:
> dmypy run -- --check-untyped-defs a.py b.py
Success: no issues found in 2 source files
  1. Edit only b.py, flipping the type of SCALE:
# b.py
SCALE: str = "3"
  1. Re-run the same daemon. The changed type of b.SCALE triggers a reprocess of a.func. Even though the function is still decorated with @no_type_check, it gets type checked:
> dmypy run -- --check-untyped-defs a.py b.py
a.py:8: error: Incompatible types in assignment (expression has type "str", variable has type "int")  [assignment]
a.py:9: error: Incompatible types in assignment (expression has type "str", variable has type "int")  [assignment]
Found 2 errors in 1 file (checked 2 source files)
  1. This only happens in incremental mode. A cold daemon shows no errors:
> dmypy stop && dmypy run -- --check-untyped-defs a.py b.py
Success: no issues found in 2 source files

Disclaimer

I've read the contributor guide. This was really hard to debug, so I've employed an LLM to come up with a reproduction, find the bug in the mypy codebase and implement a fix. I've reviewed the generated code and I'm happy with its quality. Happy to iterate over the code.

@thomasbbrunner

Copy link
Copy Markdown
Author

@ilevkivskyi I cannot assign a reviewer for this PR. What's the process here? Just wait for a contributor to pick this up?

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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.

1 participant