Typing#
- class pypeworks.typing.Args(args: tuple[Any, ...] | Any, params: _ArgsAlias)#
Class that can be used to typehint the return values of a function, allowing for these return values to be named and to be assigned a default value or factory. Within pypeworks this class is used to map one Node’s outputs to another Node’s input parameters.
Consider for example the following example, wherein a node produces pairs of x and y coordinates in an incremental lineair fashion:
class Pipeline(Pipework): @Pipework.connect(input = "enter") def init(self, _) -> Args[Param[int, "x"], Param[int, "y"]]: for i in range(0, 100): yield i, i @Pipework.connect(input = "init") @Pipework.connect(output = "exit") def process(self, x : int, y : int): print(i, i)
The class may also be used standalone to construct a dictionary from a group of arguments:
sig = Args[Param[int, "x", 0], Param[int, "y", 0]] # Single argument Args(123, sig).kwargs # {'x': 123, 'y': 0} # Two arguments (passed as tuple) Args((123, 456), sig).kwargs # {'x': 123, 'y': 0}
Fundamentals#
- class pypeworks.typing.Param#
Class used in conjunction with
Args
to typehint the return values of a function. The user is expected to specify at least the type (at index 0) and the name (at index 1, or using theName
class).Note that Param-objects can be build up using both positional and named attributes. So any of the following specifications are valid:
Param[int, "x"] Param[int, Name["x"]] Param[int, "x", 0] Param[int, "x", Default[0]] Param[int, Default[0], Name["x"]]
Mixing is subject to general Python rules. So the following is not possible:
Param[int, Name["x"], 0] # Invalid
- class pypeworks.typing.Name#
Class used in conjunction with the
Param
class to assign a name to a return value.