YAML text to Python values (Effect's encoding/Yaml, based on the
yaml 2.9.0 package).
One document: block and flow collections, indentless sequence values,
multiline plain and quoted scalars, block scalars, anchors and aliases, YAML
1.1 merge keys (an unquoted << merges a mapping or a list of mappings;
explicit keys win over merged ones, earlier sources over later ones), with
the YAML 1.2 core schema (null / ~, booleans, ints including 0x
and 0o, floats, .inf, .nan; dates stay strings). Unlike YAML 1.2,
a multiline flow collection's closing bracket may sit at its parent's
indentation.
Not supported, as in Effect: compact nested block sequences (- - value),
multiline quoted scalars in flow collections, explicit complex keys, tags and
directives, recursive aliases, and document streams. Mapping keys are
strings. Malformed or unsupported text raises ValueError.
Values#
| Attribute | Type | Description |
|---|---|---|
MAX_INTEGER_DIGITS | Literal[1000] = 1000 | The most significant digits of an integer |
Functions#
parse#
parse(text) -> objectOne YAML document as Python values: mappings are dict[str, ...],
sequences list, scalars None, bool, int, float or
str. Raises ValueError for malformed or unsupported text, and for
text nested past Python's recursion limit (Effect's throws RangeError
past JavaScript's stack).
| Parameter | Type | Description |
|---|---|---|
text | str |
Returns object
def parse(text: str) -> object:
"""One YAML document as Python values: mappings are ``dict[str, ...]``,
sequences ``list``, scalars ``None``, ``bool``, ``int``, ``float`` or
``str``. Raises ``ValueError`` for malformed or unsupported text, and for
text nested past Python's recursion limit (Effect's throws ``RangeError``
past JavaScript's stack)."""
source = re.sub(r"\r\n?", "\n", text.removeprefix("\ufeff"))
lines = [_make_line(raw, i) for i, raw in enumerate(source.split("\n"))]
return parse_nested(_Parser(lines).parse)