Skip to content

Protection against using Result with if #191

Open
@last-partizan

Description

Hello, i'm doing some refactoring of my app, and wanted to use result.

Old code uses if some_func(): ... constructions, and now they're returning Result(), and this should not be treated as error in type checker.

After some testing, i found this:

from typing import NoReturn

class NoIf:
    def __bool__(self) -> NoReturn:
        raise RuntimeError()


if NoIf():
    pass

This results in error in pyright (but not in mypy)

  /tmp/test.py:6:4 - error: Invalid conditional operand of type "NoIf"
    Method __bool__ for type "NoIf" returns type "NoReturn" rather than "bool" (reportGeneralTypeIssues)

Should i make a PR adding this __bool__ override, if you think this can be useful for everyone?

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions