ParameterNamespace
- class caqtus.types.parameter.ParameterNamespace(
- content: Sequence[tuple[DottedVariableName, Expression | Self]],
Bases:
objectA nested namespace of user parameters.
Objects of this class map from a variable name of type
DottedVariableNameto either an unevaluated expression (Expression) or anotherParameterNamespace.Objects of this class are not per-say a mapping, because the variable names have a definition order and can be duplicates.
- classmethod from_mapping(
- mapping: Mapping[str | DottedVariableName, Expression | MappingNamespace],
Construct a ParameterNamespace from a mapping of strings to values.
Example
namespace = ParameterNamespace.from_mapping({ "a": 1, "b": { "c": 2, "d": 3, }, })
- items() Iterable[tuple[DottedVariableName, Expression | ParameterNamespace]]
Return an iterable of the items in the namespace.
- flatten() Iterable[tuple[DottedVariableName, Expression]]
Return an iterable of flat key-value pairs in the namespace.
The values are iterated over in their definition order in the namespace.
- get(
- parameter: DottedVariableName,
Return the expression associated with a parameter name.
In case the parameter is defined several times in the namespace, it will return the last definition.
- Raises:
KeyError, if the parameter is not present in the namespace. –
- evaluate() dict[DottedVariableName, TypeAliasForwardRef('Parameter')]
Evaluate the values in the namespace.
Each expression is evaluated within the context of the parameters evaluated before. If two declarations have the same parameter name, the last value will overwrite the first one.
- replace(
- parameter: DottedVariableName,
- expression: Expression,
Replace all occurrences of the parameter with the given value.
- names() set[DottedVariableName]
Return the names of the parameters in the namespace.