singletons.sentinel¶
Pythonic FP - Collection of singleton classes
- final class pythonic_fp.singletons.sentinel.Sentinel(sentinel_name: str)¶
Singleton classes representing sentinel values.
intended for library code, not to be exported/shared between modules
otherwise some of its intended typing guarantees may be lost
useful substitute for
None
as a hidden sentinel valueallows
None
to be stored in data structuresallows end users to choose to use
None
or()
as sentinel valuesalways equals itself (unlike
NoValue
)
Usage:
import Sentinel and then either
define
_my_sentinel: Final[Sentinel] = Sentinel('my_sentinel')
or use
Sentinel('my_sentinel')
directly
compare using either
is
andis not
or==
and!=
the
Sentinel()
value always equals itselfand never equals anything else, especially other sentinel values