pyyaml
pyyaml copied to clipboard
Mapping can be a key in YAML
The very similar issue PyYaml can't parse mappings with lists as keys #339 The valid YAML
{1: 1}: first
is expected to be loaded into a dictionary, for example
{frozenset({(1, 1)}): 'first'} # {frozenset({1: 1}.items()): 'first'}
but results in the error
>>> p=yaml.load('{1: 1}: first')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python310\lib\site-packages\yaml\__init__.py", line 114, in load
return loader.get_single_data()
File "C:\Python310\lib\site-packages\yaml\constructor.py", line 51, in get_single_data
return self.construct_document(node)
File "C:\Python310\lib\site-packages\yaml\constructor.py", line 60, in construct_document
for dummy in generator:
File "C:\Python310\lib\site-packages\yaml\constructor.py", line 413, in construct_yaml_map
value = self.construct_mapping(node)
File "C:\Python310\lib\site-packages\yaml\constructor.py", line 218, in construct_mapping
return super().construct_mapping(node, deep=deep)
File "C:\Python310\lib\site-packages\yaml\constructor.py", line 141, in construct_mapping
raise ConstructorError("while constructing a mapping", node.start_mark,
yaml.constructor.ConstructorError: while constructing a mapping
found unhashable key
in "<unicode string>", line 1, column 1:
{1: 1}: first
^
>>>
related to https://github.com/yaml/pyyaml/issues/339