xnano.utils.validation
xnano.utils.validation
¶
xnano.utils.validation
Validate fields, command parameters, and component values.
Functions:
-
layout_field_annotation–Default type annotation for layout fields without an explicit one.
-
validate_type–Validates a value against a type annotation using
pydantic_core.
infer_pydantic_core_schema_name
cached
¶
Infers the pydantic_core schema name for a given type annotation.
Parameters:
-
annotation(type) –The type to infer the schema name for.
Returns:
-
str–The
pydantic_coreschema name string for the given type.
Source code in xnano/utils/validation.py
register_validatable_type
¶
register_validatable_type(
annotation: Any,
) -> SchemaValidator
Builds and caches a SchemaValidator for a type annotation.
Supports primitives, stdlib types, generic containers, Literal,
Union, enums, TypedDict, dataclasses, and pydantic models.
Falls back to an isinstance check for unrecognised types.
Parameters:
-
annotation(Any) –The type annotation to build a validator for.
Returns:
-
SchemaValidator–A cached
SchemaValidatorfor the given annotation.
Source code in xnano/utils/validation.py
validate_type
¶
Validates a value against a type annotation using pydantic_core.
Parameters:
Returns:
-
Any–The validated (and coerced, where applicable) value.
Raises:
-
ValidationError–If
valuedoes not satisfyannotation.