Skip to content

type checking on boolean expressions #1871

Closed
@TadLeonard

Description

@TadLeonard

I came across this while reading Daniel Moisset's impression of mypy. He mentions satisfying mypy by wrapping a boolean return expression in bool(), which I think is unnecessary. Below is a simple example that mypy fails on with Incompatible return value type (got "Union[str, bool]", expected "bool"). Note that the return expression is of the form <expression> and <comparison> or <comparison>.

def bool_expr_test(line: str) -> bool:
    return line and line[0] == '"' or line[0] == "'"

Tested on 64c0acd and 0.4.3 (from pip).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions