novalue¶
- final class pythonic_fp.gadgets.sentinels.novalue.NoValue¶
Bases:
objectmissing value
Singleton class representing an actual, not potential, missing value.
While
Noneand()are frequently used as sentinel values, I prefer to think of them asNoneas returns, or returned, no values.()as an empty, possibly typed, iterable collection.
Important
Given variables
x: int | NoValue y: int | NoValue
Equality between
xandymeans both values exist and compare as equal.x == y¶y = NoValue()y = 42y = 57x = NoValue()FalseFalseFalsex = 42FalseTrueFalsex = 57FalseFalseTruex != y¶y = NoValue()y = 42y = 57x = NoValue()FalseFalseFalsex = 42FalseFalseTruex = 57FalseTrueFalseWarning
use
==or!=only in value comparisonsuse
isandis notto identity theNoValue()singleton itself
Tip
Use in a union type when creating “optional” arguments to functions and methods.
To help ensure the abstraction stays a hidden implementation detail and does not leak out into user code,
Do not export the sentinel value.
A new reference can always be generated via
NoValue().
Use
@overloadto keep theNoValuetype out of documentation and IDEs.
- __hash__() int¶
hash
- returns:
The singleton’s unique integer hash value.
- __repr__() str¶
repr string
- returns:
The string ‘NoValue()’.
- __bool__() bool¶
bool
Always falsy.
- returns:
False
- __eq__(other: object) bool¶
Equality comparison
- param other:
The object to be compared.
- returns:
Falseeven if compared to itself.
Warning
non-standard comparison semantics
always returns
Falseif one or both values are missing, then what is there to compare?
- __ne__(other: object) bool¶
not equal
- returns:
False
Warning
non-standard comparison semantics
always returns
False