Skip to content

Incorrect "Unused 'type: ignore' comment" on top-level ignore[error-code] #12076

Closed
@jonathanslenders

Description

@jonathanslenders

Bug Report

When there's a top-level type-ignore with error code, like # type: ignore[no-untyped-defs], and --warn-unused-ignores is passed, this type comment always shows up as an unused ignore, even though the type checking would fail without that comment.

To Reproduce

Create this file:

# type: ignore[no-untyped-def]

def untyped(): pass

Run using mypy test.py --strict. (which includes --warn-unused-ignores)

Expected Behavior

This should pass, because removing the type comment causes the no-untyped-def error to appear.

Actual Behavior

 $ mypy test.py   --warn-unused-ignores
test.py:1: error: Unused "type: ignore" comment
Found 1 error in 1 file (checked 1 source file)

Your Environment

Mypy 0.931, Python 3.9.9, Ubuntu 20.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-type-ignore# type: ignore comments

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions