PyYaml can't parse mappings with lists as keys
See original GitHub issueHere is an example of valid YAML from the YAML spec (example 2.11):
? [ New York Yankees,
Atlanta Braves ]
: [ 2001-07-02, 2001-08-12,
2001-08-14 ]
However, PyYaml can’t parse this:
yaml.safe_load("""? [ New York Yankees,
Atlanta Braves ]
: [ 2001-07-02, 2001-08-12,
2001-08-14 ]""")
yaml.constructor.ConstructorError: while constructing a mapping
in "<unicode string>", line 1, column 1:
? [ New York Yankees,
^
found unhashable key
in "<unicode string>", line 1, column 3:
? [ New York Yankees,
^
This must be a bug, as it violates the spec. It could be fixed by parsing the list as a tuple.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7 (6 by maintainers)
Top Results From Across the Web
PyYAML can't parse sequence of sequences - Stack Overflow
The mapping in case only has the key value pair ( type , Agricultural ), the sequence contains the mapping (with key title...
Read more >Unable to parse YAML: mapping values are not allowed here
Running your config.yml through yamllint, produced the following: 1:1 warning missing document start "---" (document-start) 13:3 error ...
Read more >A Powerful Python Trick: Custom YAML tags & PyYAML
In this simple, case one could easily load and parse the YAML into the desired Python dictionary, instantiating the Employee class where needed....
Read more >YAML: The Missing Battery in Python
To parse YAML at a low level, you'll build a syntax highlighter tool and an ... which is equivalent to a mapping without...
Read more >10 YAML tips for people who hate YAML | Enable Sysadmin
There are lots of formats for configuration files: a list of values, key and value pairs, INI files, YAML, JSON, XML, and many...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It would be cool if someone could have a look at my PR (#159). It still might need some work (what if we have circular aliases?), but if there’s something wrong in general with it, I’d like to know.
I did a PR for this last year: #159