Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Error reporting is limited when dict key is unhashable #17

@zaneb

Description

@zaneb

If you attempt to parse code that contains a mapping with an unhashable key, yaml raises a ConstructorError that tells the user exactly where the issue was. However, oyaml raises a TypeError, which may be missed by exception handling code expecting a ConstructorError, and which contains no information about where the problem occurred.

>>> def test():
...   try:
...     yaml.safe_load("{foo: bar}: baz")
...   except Exception as e:
...     print("%s: %s" % (type(e).__name__, e))
... 
>>> import yaml
>>> test()
ConstructorError: while constructing a mapping
found unacceptable key (unhashable type: 'dict')
  in "<string>", line 1, column 1:
    {foo: bar}: baz
    ^
>>> import oyaml
>>> test()
TypeError: unhashable type: 'OrderedDict'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions