Skip to content

Detect impossible condition caused by user defined __bool__ #7008

Description

@graingert

Eg with the following:

fromtypingimport*classFoo:
def__bool__(self) ->Literal[True]:
returnTruedefsome_foo() ->Foo:
...
defthrow_error():
raiseExceptionif__name__=='__main__':
print(some_foo() orthrow_error())
# ^^^^^^^^^^^^^ impossible condition, unreachable

mypy should be able to detect that the call to throw_error is unreachable

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions