Skip to content

Ignoring a specific error code still outputs "notes" and returns exit status 1 #7562

@Deimos

Description

@Deimos

Here's a minimal repro:

from datetime import datetime
from typing import Optional

a: Optional[datetime] = None
b = datetime.now()

def some_function() -> None:
    if a <= b:
        pass

Running mypy on that file with --show-error-codes and --pretty outputs:

mypy_test.py:8: error: Unsupported operand types for >= ("datetime" and "None")  [operator]
        if a <= b:
           ^
mypy_test.py:8: note: Left operand is of type "Optional[datetime]"

If I add # type: ignore on the if a <= b: line, there is no error output, as expected.

However, if I use # type: ignore[operator] instead, the output is:

mypy_test.py:8: note: Left operand is of type "Optional[datetime]"

This also gives an exit status of 1, making it seem like it returned an error.

As one step more, if I also add the --show-error-context flag, output is now:

mypy_test.py: note: In function "some_function":
mypy_test.py:8: note: Left operand is of type "Optional[datetime]"

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions