Skip to content

truthy-bool check does not check the not operator #17769

@komodovaran

Description

@komodovaran
class Foo:
    @property
    def prop(self) -> bool:
        return False


def bools_only(value: bool) -> bool:
    return value


bools_only(Foo().prop) # Standard behavior of properties
bools_only(Foo.prop) # Expected type 'bool', got 'property' instead 
bools_only(not Foo.prop) # no error after casting with `not`!

Python interprets not object as not bool(object) which doesn't seem to be covered by any checks.

Tested with Mypy 1.11.2 and Python 3.12

https://mypy-play.net/?mypy=latest&python=3.12&gist=1c5f3510b686dd0e2e04e0a9ef191a96

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions