@@ -12,7 +12,7 @@ always starts with `!`, and it appears before the node’s value; it is
1212not part of the scalar text itself.
1313
1414` yaml12 ` preserves tags by wrapping nodes in a ` Yaml ` object. A ` Yaml `
15- is a small frozen dataclass that carries the parsed ` value ` (a regular
15+ is a small immutable wrapper class that carries the parsed ` value ` (a regular
1616Python type) and the ` tag ` string. Here is an example of parsing a tagged scalar:
1717
1818``` python
@@ -158,7 +158,7 @@ true: true
158158
159159When a key can’t be represented directly as a plain Python dict key,
160160` yaml12` wraps it in `Yaml`. That preserves the original key and makes
161- it hashable (with equality defined by structure), so it can safely live
161+ it hashable (with equality defined by structure, including mapping key order ), so it can safely live
162162in a Python `dict` :
163163
164164` ` ` python
@@ -277,7 +277,7 @@ rmd_lines = [
277277 "---",
278278 "# Body that is not YAML",
279279]
280- frontmatter = parse_yaml(rmd_lines)
280+ frontmatter = parse_yaml(" \n ".join( rmd_lines) )
281281assert frontmatter == {"title": "Front matter only", "params": {"answer": 42}}
282282` ` `
283283
@@ -417,15 +417,17 @@ assert parse_yaml(text)["item"].tag == "tag:example.com,2024:widgets/gizmo"
417417
418418# ## Tag URIs
419419
420- To bypass handle resolution, use `!<...>` with a valid URI-like string :
420+ To specify a verbatim tag, use `!<...>` with a valid URI-like string. For
421+ simple tags like `gizmo`, `yaml12` normalizes `!<gizmo>` to the local tag
422+ form `!gizmo` :
421423
422424` ` ` python
423425parsed = parse_yaml("""
424426%TAG ! tag:example.com,2024:widgets/
425427---
426428item: !<gizmo> foo
427429""")
428- assert parsed["item"].tag == "gizmo"
430+ assert parsed["item"].tag == "! gizmo"
429431` ` `
430432
431433# ## Core schema tags
@@ -472,8 +474,8 @@ def binary_handler(value):
472474converted = parse_yaml(
473475 yaml_text,
474476 handlers={
475- "tag:yaml.org,2002: timestamp": ts_handler,
476- "tag:yaml.org,2002: binary": binary_handler,
477+ "!! timestamp": ts_handler,
478+ "!! binary": binary_handler,
477479 },
478480)
479481assert isinstance(converted[0], datetime) and isinstance(converted[2], (bytes, bytearray))
0 commit comments