flavored¶
Sentinel values “indexed” by hashable values of a given type.
- final class pythonic_fp.gadgets.sentinels.flavored.Sentinel¶
Bases:
GenericSentinel
Sentinel values labeled by different (hashable) flavors.
Note
Useful for union types.
A flavored
Sentinelvalue always equals itself and never equals anything else, especially other flavored sentinel values.
- static __new__(cls, flavor: H) Sentinel¶
new
- param flavor:
Hashable value determining which flavored Sentinel to return.
- returns:
The Sentinel(flavor) singleton instance.
- __reduce__() tuple[type[Sentinel], tuple[H]]¶
reduce
Tell
pickleandcopyhow to reconstruct the sentinel: callSentinel(flavor)rather than rebuilding the object directly.reconstruction goes through
__new__, so the flavor cache is consultedunpickling returns the existing singleton of that flavor, or creates and caches it in a fresh interpreter
copyanddeepcopyuse the same protocol, so they return the singleton unchanged
- returns:
The pair
(Sentinel, (flavor,)), whichpicklecalls to rebuild the sentinel.
Important
Without this,
picklewould construct a duplicateSentineloutside the flavor cache, andiscomparisons against it would silently fail.
- __repr__() str¶
repr string
Construct string ‘Sentinel(flavor)’ where the flavor is displayed with
repr().- returns:
A string to reproduce the flavored sentinel.
- __str__() str¶
user string
Construct string ‘Sentinel(flavor)’ where the flavor is displayed with
str().- returns:
A string meaningful to an end user.
- flavor() H¶
get flavor
- returns:
The sentinel’s flavor.
- __annotate_func__()¶
The type of the None singleton.