Skip to content

Boolean Types

IsTrueLike

IsTrueLike(*repr_args: Any, **repr_kwargs: Any)

Bases: DirtyEquals[bool]

Check if the value is True like. IsTrueLike allows comparison to anything and effectively uses just return bool(other).

Example of basic usage:

IsTrueLike
from dirty_equals import IsTrueLike

assert True == IsTrueLike
assert 1 == IsTrueLike
assert 'true' == IsTrueLike
assert 'foobar' == IsTrueLike  # any non-empty string is "True"
assert '' != IsTrueLike
assert [1] == IsTrueLike
assert {} != IsTrueLike
assert None != IsTrueLike

Parameters:

Name Type Description Default
*repr_args Any

unnamed args to be used in __repr__

()
**repr_kwargs Any

named args to be used in __repr__

{}

IsFalseLike

IsFalseLike(*, allow_strings: bool = False)

Bases: DirtyEquals[bool]

Check if the value is False like. IsFalseLike allows comparison to anything and effectively uses return not bool(other) (with string checks if allow_strings=True is set).

Parameters:

Name Type Description Default
allow_strings bool

if True, allow comparisons to False like strings, case-insensitive, allows '', 'false' and any string where float(other) == 0 (e.g. '0').

False

Example of basic usage:

IsFalseLike
from dirty_equals import IsFalseLike

assert False == IsFalseLike
assert 0 == IsFalseLike
assert 'false' == IsFalseLike(allow_strings=True)
assert '0' == IsFalseLike(allow_strings=True)
assert 'foobar' != IsFalseLike(allow_strings=True)
assert 'false' != IsFalseLike
assert 'True' != IsFalseLike(allow_strings=True)
assert [1] != IsFalseLike
assert {} == IsFalseLike
assert None == IsFalseLike
assert '' == IsFalseLike(allow_strings=True)
assert '' == IsFalseLike