Yaml
A wrapper for unhashable mapping keys and tagged YAML nodes.
Usage
Yaml()Yaml serves two purposes:
- Represent a
listordictas a mapping key. parse_yaml() and read_yaml() wrap keys that Python cannot hash; you can also wrap alistordictyourself. - Represent a tagged YAML node. Pass a value and tag to Yaml when writing with format_yaml() or write_yaml(). When reading, parse_yaml() and read_yaml() use Yaml to preserve tags outside the YAML 1.2 core schema when no matching handler is supplied.
Indexing, iteration, and len() operate on the wrapped list or dict. Yaml objects are hashable, and their value and tag attributes are read-only. For list and dict values, hashing and equality use the tag and the contents at construction, including dict item order.
Parameters
value: object-
The wrapped value.
tag: str | None-
The YAML tag, or
Nonefor an untagged value. Simple local tag names are stored with a leading!: both"gizmo"and"!<gizmo>"become"!gizmo".
Examples
>>> Yaml("1 + x", "!expr")Yaml(value='1 + x', tag='!expr')
>>> parse_yaml("? [a, b]\n: 1"){Yaml(['a', 'b']): 1}
Attributes
| Name | Description |
|---|---|
| value | The wrapped value. |
| tag |
The YAML tag in normalized form, or None for an untagged value.
|
value
The wrapped value.
value: Any
tag
The YAML tag in normalized form, or None for an untagged value.
tag: str | None