In python the value of None is the same as no value.
def func():
return NoneIs equivalent to:
def func():
returnHowever this can cause problem when chaining functions together. For example:
def func_a():
return # Shadow returns None
def func_b():
# zero args expected
return "egg"
## Run chain example
value = func_a()
if value:
func_b(value)
else:
func_b()
# TypeError: func_b() takes 0 positional arguments but 1 was givenThis occurs because value is populated with None, even though we don't explicitly return a value from func_a.
To correct this, we apply a sentinal value. A distinct object that is represents the absence of a value.
_SENTINAL = object()
def func_a():
return _SENTINAL
def func_b():
# no value given to this
return "egg"
## Run chain example
value = func_a()
if value is not _SENTINAL:
func_b(value)
else:
func_b(func_a())With this we can detect when a function has explicitly returned no value and handle it accordingly.
Because Hyperway chains together multiple functions, sentinal allows functions to explicitly return no value
When building a node, apply your preferred sentinal value:
UNDEFINED = object() # considered a singleton.
def foo():
return UNDEFINED
unit = as_unit(foo, sentinal=UNDEFINED)
connection = make_edge(foo, unit)When the node is executed, if foo returns UNDEFINED, Hyperway will treat this as no value and will not pass it to downstream nodes.