ccsds_ndm.model_quantity

Validation and quantity support for xsdata model classes.

Patches __setattr__ on container dataclasses so that:

  • Already-wrapped values (e.g. LengthType) pass through unchanged.

  • pint / astropy Quantity objects are converted to the correct wrapper type with unit conversion and dimensional validation.

  • Plain numbers, strings, and other invalid types raise TypeError.

  • None is allowed on optional fields.

Also patches a .q() method on wrapper types (dataclasses with value and units fields) that returns a pint or astropy Quantity, controlled by a global mode flag.

Patching runs automatically when this module is imported.

Functions

get_auto_convert()

Return whether automatic unit conversion is enabled.

get_quantity_mode()

Return the current global quantity mode.

set_auto_convert(enabled)

Enable or disable automatic unit conversion on Quantity assignment.

set_quantity_mode(mode)

Set the global quantity mode for .q() on wrapper types.

Classes

QuantityMode(*values)

Quantity backend selection.

class QuantityMode(*values)[source]

Quantity backend selection.

get_auto_convert()[source]

Return whether automatic unit conversion is enabled.

Return type:

bool

get_quantity_mode()[source]

Return the current global quantity mode.

Return type:

QuantityMode

set_auto_convert(enabled)[source]

Enable or disable automatic unit conversion on Quantity assignment.

Parameters:

enabled (object)

Return type:

None

set_quantity_mode(mode)[source]

Set the global quantity mode for .q() on wrapper types.

Parameters:

mode (object)

Return type:

None