Skip to content

[BUG] Type ignore annotation used on operating system specific code #9242

Closed
@ChamNouki

Description

@ChamNouki

Hello here,

I try to type check the following code using mypy. As there are specific operating system lines of code, I have to tell to mypy to ignore them.

def is_user_admin() -> bool:
    try:
        system = platform.system()

        if system in ['Darwin', 'Linux']:
            return os.getuid() == 0  # type: ignore[attr-defined, no-any-return]

        if system == 'Windows':
            return ctypes.windll.shell32.IsUserAnAdmin() == 1  # type: ignore[attr-defined, no-any-return]

    except AttributeError:
        logger.info(f"Failed to determine if current user is an admin on {system} operating system.")

    raise AdminStateUnknownException

As expected, types are ignored but I have the following error (which seems to be legit too) running the command python -m mypy --strict admin.py

mumgram/admin.py:15: error: unused 'type: ignore' comment
                return os.getuid() == 0  # type: ignore[attr-defined, no-any-return]
                ^
Found 1 error in 1 file (checked 1 source file)

Obviously I need those annotations cause we have developpers using Windows and other using OSX/Linux.

I try to use the --warn-unused-ignore parameter for the command (python -m mypy --strict admin.py --warn-unused-ignore) but unfortunatly that doesn't seems to work and the error is still an error (breaking my CI 😱 !).

I use Python 3.7.7 64-bit and mypy 0.782

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions