Sentinel
MISSING is an exported marker object representing an omitted value. It distinguishes omission from explicit None, False, 0 and empty strings. The page title “Sentinel” names this pattern; there is no public Sentinel class to instantiate.
Import and direct use
Section titled “Import and direct use”Use the canonical public package import and compare by identity. A default argument and a dictionary lookup can both retain the distinction between missing and explicitly empty data.
from orionis.support.types import MISSING
def describe(value=MISSING) -> str: return "omitted" if value is MISSING else "supplied"
assert describe() == "omitted"assert describe(None) == "supplied"assert describe(False) == "supplied"assert describe(0) == "supplied"assert describe("") == "supplied"
payload = {"name": None}assert payload.get("name", MISSING) is Noneassert payload.get("email", MISSING) is MISSINGDependency injection
Section titled “Dependency injection”Import and pass MISSING, or use it as a default argument. It is an already-created value, not a concrete injectable service class. There is no constructor-based Sentinel dependency to resolve and no container initialization is required. The implementation type _MISSING_TYPE is private.
__repr__(self) -> str
Section titled “__repr__(self) -> str”Returns the exact string "<MISSING>" without changing the marker. The inherited str() behavior also uses this representation; the text is diagnostic output, not a serialized identity.
from orionis.support.types import MISSING
assert repr(MISSING) == "<MISSING>"assert str(MISSING) == "<MISSING>"__bool__(self) -> bool
Section titled “__bool__(self) -> bool”Always returns False. not MISSING is True, and conditions take the false branch. This does not make the marker equal to False, None or zero. A truthiness test cannot distinguish all absent and explicit falsy values; use is MISSING.
from orionis.support.types import MISSING
assert bool(MISSING) is Falseassert not MISSINGassert ("present" if MISSING else "absent") == "absent"assert MISSING is not Falseassert MISSING != 0assert MISSING is not NoneIdentity, equality and hashing
Section titled “Identity, equality and hashing”The private implementation class defines no equality or hash override. Its instances use ordinary identity equality and object hashing, so the imported marker can be a dictionary key or set member. Importing MISSING repeatedly returns the same object. The implementation class does not enforce singleton construction: a new instance made from type(MISSING) is a different object with the same representation. Application code should import the exported marker.
from orionis.support.types import MISSINGfrom orionis.support.types.sentinel import MISSING as SAME_MARKER
assert SAME_MARKER is MISSINGassert MISSING == SAME_MARKERassert {MISSING: "absent"}[SAME_MARKER] == "absent"assert MISSING in {MISSING}another = type(MISSING)()assert another is not MISSINGassert another != MISSINGassert repr(another) == repr(MISSING)Python copy and serialization
Section titled “Python copy and serialization”No __copy__, __deepcopy__ or custom pickle reduction is defined. Standard shallow copy, deep copy and pickle reconstruction each create a different marker instance: their result is not MISSING under identity comparison. Do not copy or pickle the marker when later code relies on is MISSING; preserve the imported object or encode absence explicitly. JSON does not serialize it by default and raises TypeError.
import copyimport jsonimport picklefrom orionis.support.types import MISSING
for result in ( copy.copy(MISSING), copy.deepcopy(MISSING), pickle.loads(pickle.dumps(MISSING)),): assert result is not MISSING assert repr(result) == "<MISSING>" assert bool(result) is False
try: json.dumps({"value": MISSING})except TypeError: passThe marker defines no other public methods, properties, mapping operations or iteration protocol.