PyPI: pythonic-fp-booleans¶
PyPI project pythonic-fp-booleans part of the pythonic-fp namespace projects.
PyPI version 1.1.2 release.
Subtypable Boolean like classes¶
While still compatible with Python shortcut logic, these classes can be non-shortcut logically composed with Python’s bitwise operators. These classes are implemented with the Singleton Pattern.
Covariant class hierarchy¶

Contravariant non-shortcut “bitwise” operators¶
Boolean operation |
symbol |
dunder |
|---|---|---|
not |
|
__invert__ |
and |
|
__and__ |
or |
|
__or__ |
xor |
|
__xor__ |
These operators are contravariant, that is they will return the instance of the latest common ancestor of their arguments. More specifically, the instance returned will have the type of the least upper bound in the inheritance graph of the classes of the two arguments.
Warning
These “bitwise” operators could raise TypeError exceptions
when applied against an SBool and objects not descended
from int.
Classes¶
Class SBool¶
Base of the hierarchy.
Like Python’s built-in bool, SBool is a subclass of int,
unlike bool, class SBool can be further subclassed.
Class FBool¶
For when you need to deal with different “flavors” of the truth.
Each “flavor” corresponds to a hashable value. Instances of FBool
are invariant in their flavor. Best to think of the “flavor” as an
index.
Class TF_Bool¶
Class TF_Bool consists of just two disjoint subclasses, each one
a singleton.
class
T_Boolis the always truthyTF_Boolsubtypeclass
F_Boolis the always falsyTF_Boolsubtype
Getting Started
Documentation