ParameterNamespace

class caqtus.types.parameter.ParameterNamespace(
content: Sequence[tuple[DottedVariableName, Expression | Self]],
)

Bases: object

A nested namespace of user parameters.

Objects of this class map from a variable name of type DottedVariableName to either an unevaluated expression (Expression) or another ParameterNamespace.

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],
) Self

Construct a ParameterNamespace from a mapping of strings to values.

Example

namespace = ParameterNamespace.from_mapping({
    "a": 1,
    "b": {
        "c": 2,
        "d": 3,
    },
})
classmethod empty() Self

Return an empty namespace.

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,
) Expression

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,
) None

Replace all occurrences of the parameter with the given value.

names() set[DottedVariableName]

Return the names of the parameters in the namespace.