python-stdlib-sentinels
python-stdlib-sentinels copied to clipboard
add: truthy for bool evaluation
As described in #12, Sentinels truthyness depends on the context of the sentinel. This allows us to set what the sentinel can mean, and by default sentinels are ambiguous and forces the user to give it a meaning.
Example
from sentinels import Sentinel
EOF = Sentinel('EOF')
# This will return a `ValueError` since EOF doesn't have a Boolean representation
# bool(EOF)
# However, we can compare a value with EOF and that does have a Boolean representation
line= read_line(file)
print(line is EOF)
Undefined = Sentinel('undefined', truthy=False)
bool(Undefined)
# >> False
Success = Sentinel('success', truthy=True)
bool(Success )
# >> True
I haven't updated the documents yet. If this get's approved, I will update it then
any update on this @taleinat ?