Thanks to visit codestin.com
Credit goes to github.com

Skip to content

1.16 regression: --warn-unused-ignore now complains in ignored-but-correct places #19237

Description

@asottile-sentry

this appears to have changed behaviour in mypy 1.15 -- I personally prefer the behaviour in 1.15 but would understand if it needed to change. I don't see it mentioned in the changelog however

Bug Report

we're working on incrementally typing a large codebase -- often this means fixing a particular callsite or file at a time (sometimes by intentionally ignoring errors unfortunately)

it seems that in a module with a particular error code (temporarily) disabled, --warn-unused-ignores will complain about a "correct" type ignore (I say "correct" here as it will complain when the file is no longer blocklisted) -- will provide a small example below

To Reproduce

# t.py
def f() -> None:
    x: int = 'hi'  # type: ignore[assignment]
[mypy]
warn_unused_ignores = true
[mypy-t]
disable_error_code = assignment

Expected Behavior

$ mypy --version
mypy 1.15.0 (compiled: yes)
$ mypy t.py
Success: no issues found in 1 source file

Actual Behavior

$ mypy --version
mypy 1.16.0 (compiled: yes)
$ mypy t.py
t.py:2: error: Unused "type: ignore" comment  [unused-ignore]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.16.0 (regression from 1.15.0)
  • Mypy command-line flags: (see above)
  • Mypy configuration options from mypy.ini (and other config files): (see above)
  • Python version used: 3.13.1

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions