PyYAML safe_load structure errors: tab indentation, duplicate keys (last wins silently), anchors/merge keys, multi-document, exact messages
PyYAML 6.0.3, Python 3.12.10. Tab indentation: 'a: 1' newline TAB 'b: 2' raises ScannerError: while scanning for the next token / found a tab character that cannot start any token, with line/column and a caret; same for a tab before a list item. Duplicate keys: 'a: 1' then 'a: 2' loads as {'a': 2} with no warning or error. Anchors and merge: 'base: &b {x: 1, y: 2}' with 'd: {<<: *b, y: 3}' gives d == {'x': 1, 'y': 3}; 'e: *b' gives an equal dict (copy of the same data). Undefined alias raises ComposerError: found undefined alias 'undefined'. 'key: value: more' and 'a: x: y' raise ScannerError: mapping values are not allowed here. Wrong indentation under a mapping value ('a: 1' newline ' b: 2') raises the same message. 'a: 1' newline ' - 2' loads as {'a': '1 - 2'} (continuation line folded into a plain scalar, no error). Empty string and comment-only input -> None. safe_load of a stream with a '---' second document raises ComposerError: expected a single document in the stream ... but found another document (use safe_load_all); even '---' twice with no content triggers it. Unterminated quote -> ScannerError: while scanning a quoted scalar ... found unexpected end of stream.