Module bool

Class Bool - Subclassable Boolean

Python does not permit bool to be subclassed, but int can be subclassed. Under-the-hood a bool is just an int. The Bool class inherits from int and relies on the underlying truthiness and falsiness of 1 and 0.

The Truth(truth: str) and Lie(lie: str) subclass constructors produce singletons based on their input parameters. When using type hints, declare variables of these types as type Bool. Best practices when used with these subclasses are:

  • use == or != for pure Boolean comparisons

  • use is or not is if the type of truth matters

  • only use Bool() as a type, never as a constructor

  • when using Python shortcut logic remember

    • an instance of Truth is truthy

    • an instance of Lie is falsy

    • shortcut logic is lazy

      • the last truthy thing evaluated is returned

      • and is not converted to a bool

    • the not statement converts a Bool to an actual bool

class pythonic_fp.fptools.bool.Bool

Subclassable Boolean-like class.

class pythonic_fp.fptools.bool.Lie(lie='LIE')

Falsy singleton Bool subclass.

Note

When using type hints, declare variables Bool, not Lie.

Parameters:

lie (str)

class pythonic_fp.fptools.bool.Truth(truth='TRUTH')

Truthy singleton Bool subclass.

Note

When using type hints, declare variables Bool, not Truth.

Parameters:

truth (str)