Skip to content

warn_unused_ignores vs. OS-specific code #12768

@crusaderky

Description

@crusaderky

I'd like to add to my setup.cfg

[mypy]
warn_unused_ignores = True
warn_redundant_casts = True

However, I can't find a way to make it work because there are developers on the project that need to run mypy on Windows, and in the code there are OS-specific lines, e.g.

import os
import sys

if sys.platform != "win32":
    os.sysconf("SC_IOV_MAX")  # type: ignore

See matching lines in typeshed:
https://github.com/python/typeshed/blob/963b8aa2f77187f381f75d9630b3d021aff55132/stdlib/os/__init__.pyi#L990-L994

With # type: ignore, mypy fails on Linux due to warn-unused-ignores.
Without it, it fails on Windows.

Is there a way to make it work, besides manually enabling the flag once in a while, do a one-off clean-up, and then disabling it?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions