novalue

Singleton class representing an actually, not potentially, missing value.

NoValue() is a singleton object representing a missing value.

While None and () are frequently used as sentinel values, I prefer to think of them as

  • None: Returns, or returned, no values.

  • (): An empty, possibly typed, iterable collection.

Important

Given variables

x: int | NoValue
y: int | NoValue

Equality between x and y means both values exist and compare as equal. If one or both of theses values are missing, then what is there to compare?

x == y

x∖y

NoValue()

42

57

NoValue()

false

false

false

42

false

true

false

57

false

false

true

Similarly for not equals.

x != y:wq

x∖y

NoValue()

42

57

NoValue()

false

false

false

42

false

false

true

57

false

true

false

Warning

Only use == or != in value comparisons. To directly identity the NoValue singleton, use is and is not instead.

Note

Threadsafe.

Tip

Use as a hidden implementation detail when creating “optional” arguments to functions and methods.

To help ensure the abstraction does not leak,

  • Do not export the sentinel value.

  • Use @overload to keep the NoValue type out of documentation and IDEs.

final class pythonic_fp.gadgets.sentinels.novalue.NoValue
Returns:

The NoValue singleton instance.

__eq__(other: object) bool
Returns:

False

__ne__(other: object) bool
Returns:

False