Skip to content

yggdrasil.data.types.parser

parser

ParsedDataType dataclass

ParsedDataType(
    type_id: DataTypeId,
    metadata: "DataTypeMetadata" = (lambda: _EMPTY_METADATA)(),
    name: str | None = None,
    children: tuple["ParsedDataType", ...] = (),
)

from_ classmethod

from_(value: str, *, default: Any = ...) -> 'ParsedDataType'

Parse a DataType string.

On parse failure the dispatch is driven by default:

  • default = ... (the sentinel default) — re-raise the underlying :class:ValueError. Use this when the caller treats parse failure as a programming error.
  • default is a :class:ParsedDataType — return it as-is.
  • default is a :class:DataTypeId — wrap into a bare :class:ParsedDataType with no metadata.
  • Anything else (including None) — collapse to :data:DataTypeId.OBJECT, the "I don't know what this is, treat it as opaque" type. Strings used to land here too; OBJECT keeps the value untouched whereas STRING would have coerced through str() on cast.

Successful parses are memoized via :func:_parse_cached so a schema that mentions map<string, struct<...>> a million times only walks the AST once. Failures are not cached — each call re-raises so a fix in the input doesn't get masked.

parse_data_type

parse_data_type(value: str, *, default: Any = ...) -> ParsedDataType

Module-level alias for :meth:ParsedDataType.from_.

See that method for the default semantics — passing :data:... raises on failure, anything else is a fallback.