param.output#
- param.output(func, *output, **kw)[source]#
Annotate a method to declare its outputs with specific types.
The
outputdecorator allows annotating a method in aParameterizedclass to declare the types of the values it returns. This provides metadata for the method’s outputs, which can be queried using theoutputs()method. Outputs can be declared as unnamed, named, or typed, and the decorator supports multiple outputs.- Parameters:
func (callable) – The method being annotated.
*output (tuple or Parameter or type, optional) –
Positional arguments to declare outputs. Can include:
**kw (dict, optional) –
Keyword arguments mapping output names to types. Types can be:
Parameterinstances.Python object types, which will be converted to
ClassSelector.
- Returns:
The decorated method with annotated outputs.
- Return type:
callable
- Raises:
ValueError – If an invalid type is provided for an output or duplicate names are used for multiple outputs.
Notes
Unnamed outputs default to the method name.
Python types are converted to
ClassSelectorinstances.If no arguments are provided, the output is assumed to be an object without a specific type.
Examples
Declare a method with an unspecified output type:
>>> import param >>> class MyClass(param.Parameterized): ... @param.output() ... def my_method(self): ... return 42
Query the outputs:
>>> MyClass().param.outputs() {'my_method': (<param.parameterized.Parameter at 0x7f12f8d334c0>, <bound method MyClass.my_method of MyClass(name='MyClass00004')>, None)}
Declare a method with a specified type:
>>> class MyClass(param.Parameterized): ... @param.output(param.Number()) ... def my_method(self): ... return 42.0
Use a custom output name and type:
>>> class MyClass(param.Parameterized): ... @param.output(custom_name=param.Number()) ... def my_method(self): ... return 42.0
Declare multiple outputs using keyword arguments:
>>> class MyClass(param.Parameterized): ... @param.output(number=param.Number(), string=param.String()) ... def my_method(self): ... return 42.0, "hello"
Declare multiple outputs using tuples:
>>> class MyClass(param.Parameterized): ... @param.output(('number', param.Number()), ('string', param.String())) ... def my_method(self): ... return 42.0, "hello"
Declare a method returning a Python object type:
>>> class MyClass(param.Parameterized): ... @param.output(int) ... def my_method(self): ... return 42