[Python] Mypy complaining about [no-any-return] rule being violated for obvious boolean...

Discussão em 'Python' iniciado por Stack, Junho 9, 2025.

  1. Stack

    Stack Membro Participativo

    The following code throws a mypy error:

    from typing import Dict, Any

    def asd(x: Dict[str, Any]) -> bool:
    return x['a'] == 1

    asd({"x": 2})


    IMO it doesn't matter what is passed as a dict. x['a'] == 1 should always be a boolean. But mypy complains with:

    test.py:4: error: Returning Any from function declared to return "bool" [no-any-return]


    Any Idea how to fix is besides peppering our codebase with # type: ignore[no-any-return]?

    my setup.cfg for reference:

    namespace_packages = True
    explicit_package_bases = True
    check_untyped_defs = True
    warn_return_any = True
    warn_unused_ignores = True
    show_error_codes = True

    Continue reading...

Compartilhe esta Página