nat.data_models.gated_field_mixin#

Classes#

GatedFieldMixinConfig

Configuration for a gated field mixin.

GatedFieldMixin

A mixin that gates a field based on specified keys.

Module Contents#

class GatedFieldMixinConfig#

Configuration for a gated field mixin.

field_name: str#
default_if_supported: object | None#
unsupported: collections.abc.Sequence[re.Pattern[str]] | None#
supported: collections.abc.Sequence[re.Pattern[str]] | None#
keys: collections.abc.Sequence[str]#
class GatedFieldMixin#

A mixin that gates a field based on specified keys.

This should be used to automatically validate a field based on a given key.

Parameters#

field_name: str

The name of the field.

default_if_supported: object | None

The default value of the field if it is supported for the key.

keys: Sequence[str]

A sequence of keys that are used to validate the field.

unsupported: Sequence[Pattern[str]] | None

A sequence of regex patterns that match the key names NOT supported for the field. Defaults to None.

supported: Sequence[Pattern[str]] | None

A sequence of regex patterns that match the key names supported for the field. Defaults to None.

classmethod _setup_direct_mixin(
field_name: str,
default_if_supported: object | None,
unsupported: collections.abc.Sequence[re.Pattern[str]] | None,
supported: collections.abc.Sequence[re.Pattern[str]] | None,
keys: collections.abc.Sequence[str],
) None#

Set up a class that directly inherits from GatedFieldMixin.

classmethod _validate_mixin_parameters(
unsupported: collections.abc.Sequence[re.Pattern[str]] | None,
supported: collections.abc.Sequence[re.Pattern[str]] | None,
keys: collections.abc.Sequence[str],
) None#

Validate that all required parameters are provided.

classmethod _create_gated_field_validator(
field_name: str,
default_if_supported: object | None,
unsupported: collections.abc.Sequence[re.Pattern[str]] | None,
supported: collections.abc.Sequence[re.Pattern[str]] | None,
keys: collections.abc.Sequence[str],
)#

Create the model validator function.

classmethod _check_field_support(
instance: object,
unsupported: collections.abc.Sequence[re.Pattern[str]] | None,
supported: collections.abc.Sequence[re.Pattern[str]] | None,
keys: collections.abc.Sequence[str],
) bool#

Check if a specific field is supported based on its configuration and keys.

classmethod _find_blocking_key(
instance: object,
unsupported: collections.abc.Sequence[re.Pattern[str]] | None,
supported: collections.abc.Sequence[re.Pattern[str]] | None,
keys: collections.abc.Sequence[str],
) str#

Find which key is blocking the field.

classmethod _collect_all_mixin_configs() list[GatedFieldMixinConfig]#

Collect all mixin configurations from base classes.

classmethod _create_combined_validator(
all_mixins: list[GatedFieldMixinConfig],
) None#

Create a combined validator that handles all fields.