-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
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]"