Unexpected parsing errors on invalid input
ruamel.yaml is a YAML 1.2 parser/emitter for Python
Brought to you by:
anthon
On certain invalid input, ruamel.yaml parses the input as valid and then later raises a nonsensical exception, rather than something derived from YAMLError
. The code provided below causes a TypeError: unhashable type: 'dict'
, because it attempts to use a dict as the key to another dict.
This is not a serious issue on its own, but might indicate a more serious parsing bug.
from ruamel import yaml as ruamel_yaml ryaml = ruamel_yaml.YAML(typ="safe", pure=True) data = '?\r- b}:\r' list(ryaml.load_all(data))
Other invalid YAML causes the same error but with lists, and the invalid YAML -_
causes a ValueError
because ruamel.yaml tries to parse it as an integer.