question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PyYaml can't parse mappings with lists as keys

See original GitHub issue

Here 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:open
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
perlpunkcommented, Sep 21, 2019

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.

1reaction
perlpunkcommented, Sep 19, 2019

I did a PR for this last year: #159

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found