Skip to content

type ignore under --strict should respect python version checks #10787

Closed
@nipunn1313

Description

@nipunn1313

Bug Report

Using this feature:
https://mypy.readthedocs.io/en/stable/common_issues.html#python-version-and-system-platform-checks
Expecting to be able to # type: ignore conditionally by python version.

To Reproduce

import sys
from typing import Text
x = "hi"  # type: str
y = "hi"  # type: Text
if sys.version_info[0] >= 3:
    x = y
else:
    x = y  # type: ignore

https://mypy-play.net/?mypy=latest&python=3.10&flags=strict&gist=831f7b62f21f6c34b2ef4b490b22e0a0

Expected Behavior

Expected no errors when run targeting both python 3.10 and 2.7

Actual Behavior

Under targeting python 3.10, we see

main.py:8: error: unused "type: ignore" comment
Found 1 error in 1 file (checked 1 source file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions