Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dottedDict does not work with yaml.dump #18

Open
cmeissner opened this issue Feb 8, 2021 · 0 comments
Open

dottedDict does not work with yaml.dump #18

cmeissner opened this issue Feb 8, 2021 · 0 comments

Comments

@cmeissner
Copy link

If I try to dump a dottedDict via yaml.dump I get a KeyError.

To reproduce the behavior I use the following code:

#!/usr/bin/env python

import yaml

from dotted.utils import dot

path = 'foo.bar.baz'

data = dict(foo=dict(bar=dict(baz='blafasel')))
data = dot(data)

print(data)
print(data[path])

print(yaml.dump(data))

If you run this script the following Execption is raised:

$ ./travers_to_dict.py
{'foo': {'bar': {'baz': 'blafasel'}}}
blafasel
Traceback (most recent call last):
  File "./travers_to_dict.py", line 15, in <module>
    print(yaml.dump(data))
  File "/home/nero/.pyenv/versions/traverse_to_dict/lib/python3.8/site-packages/yaml/__init__.py", line 290, in dump
    return dump_all([data], stream, Dumper=Dumper, **kwds)
  File "/home/nero/.pyenv/versions/traverse_to_dict/lib/python3.8/site-packages/yaml/__init__.py", line 278, in dump_all
    dumper.represent(data)
  File "/home/nero/.pyenv/versions/traverse_to_dict/lib/python3.8/site-packages/yaml/representer.py", line 27, in represent
    node = self.represent_data(data)
  File "/home/nero/.pyenv/versions/traverse_to_dict/lib/python3.8/site-packages/yaml/representer.py", line 52, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "/home/nero/.pyenv/versions/traverse_to_dict/lib/python3.8/site-packages/yaml/representer.py", line 317, in represent_object
    reduce = data.__reduce_ex__(2)
  File "/home/nero/.pyenv/versions/traverse_to_dict/lib/python3.8/site-packages/dotted/collection.py", line 266, in __getitem__
    return self.store[key]
KeyError: '__getstate__'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant