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

benedict.to_json returns empty dict for benedict from generator #38

Closed
kranonetka opened this issue Sep 29, 2020 · 1 comment
Closed
Assignees
Labels
bug Something isn't working

Comments

@kranonetka
Copy link

Python version
Python 3.8.3

Package version
python-benedict==0.21.0

Current behavior (bug description)
bededict.to_json for benedict from generator returns '{}' instead of json dumped dict

Expected behavior
bededict.to_json should return actual json dumped dict

Steps to reproduce

from benedict import benedict


def gen_dict():
    for k, v in enumerate('abcd'):
        yield k, v


if __name__ == '__main__':
    b = benedict(gen_dict())
    assert b == {0: 'a', 1: 'b', 2: 'c', 3: 'd'}
    assert b.to_json()  ==  '{"0": "a", "1": "b", "2": "c", "3": "d"}'

But if recast benedict to dict and back to benedict it works fine

if __name__ == '__main__':
    b = benedict(gen_dict())
    b = benedict(dict(b))
    assert b == {0: 'a', 1: 'b', 2: 'c', 3: 'd'}
    assert b.to_json()  ==  '{"0": "a", "1": "b", "2": "c", "3": "d"}'
@kranonetka kranonetka added the bug Something isn't working label Sep 29, 2020
@fabiocaccamo
Copy link
Owner

fabiocaccamo commented Sep 30, 2020

You can upgrade to 0.21.1 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants