ska_sdp_piper.piper.piper_undefined module

class ska_sdp_piper.piper.piper_undefined.PiperUndefined[source]

Bases: object

Sentinel class to represent an uninitialized configuration parameter.

In the Piper framework, developers must provide default values so that configurations can be dumped to YAML. However, standard defaults like None are often valid configuration values themselves.

This class provides a unique sentinel, PIPER_UNDEFINED, to explicitly mark parameters that must be provided by the user at runtime, distinguishing them from both None and valid data.

__json_repr__

The string representation used when serializing the sentinel to JSON.

Type:

str

static check(value)[source]

Check if a value is undefined, either by matching the JSON representation or being the PIPER_UNDEFINED singleton.

Parameters:

value (Any) -- The value to check.

Return type:

bool

Returns:

True if value is equivalent of PIPER_UNDEFINED, otherwise False .

static validate(value, handler, info)[source]

Validate if the value is the PIPER_UNDEFINED sentinel. If the validation context doesn't allow PIPER_UNDEFINED values, then raise exceptions. This must be used as a "wrap"-type validator for a pydantic field.

Parameters:
  • value (Any) -- The value to be validated.

  • handler (Callable) -- The next validation handler in the Pydantic chain.

  • info (ValidationInfo) -- Pydantic validation context and metadata.

Return type:

Any

Returns:

If value is a equivalent of PIPER_UNDEFINED, then the PIPER_UNDEFINED sentinel. Else, the result of the pyndatic's default validation handler.

Raises:

AssertionError -- If the value is PIPER_UNDEFINED but the validation context specifically disallows unset fields (allow_unset=False).

static serialize(value, handler, info)[source]

Serialize the PIPER_UNDEFINED sentinel based on the output mode. If value is

Parameters:
  • value (Any) -- The value to serialize.

  • handler (Callable) -- The next serialization handler in the chain.

  • info (FieldSerializationInfo) -- Metadata about the serialization process, including the mode.

Return type:

Any

Returns:

If value is a equivalent of PIPER_UNDEFINED, then either:

  • the string "!__PIPER_UNDEFINED__!" if mode is 'json'

  • otherwise the PIPER_UNDEFINED object.

Else, the result of the pyndatic's default serializer handler.

static annotate(annotation)[source]

Wraps a given type annotation with serializer and deserializer for the PIPER_UNDEFINED. Also sets the default value to PIPER_UNDEFINED. If required, caller should ensure that default value is not overriden by other ways of definining a pydantic field default.

Return type:

type[TypeVar(Generic Type)]

ska_sdp_piper.piper.piper_undefined.PIPER_UNDEFINED = <PIPER_UNDEFINED>

The singleton instance of the PiperUndefined sentinel used across the Piper framework to denote config parameters with undefined values while defining the stage. User must provide values for such parameters while running the pipeline.