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

Error message for unflatten with duplicated key is not clear #14

Open
ianlini opened this issue Sep 13, 2019 · 0 comments
Open

Error message for unflatten with duplicated key is not clear #14

ianlini opened this issue Sep 13, 2019 · 0 comments

Comments

@ianlini
Copy link
Owner

ianlini commented Sep 13, 2019

Original error:

In [4]: unflatten({1: ('a', 'b'), 2: ('a', 'b')}, inverse=True)                                                                                                                                                   
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-9f138cfe18d2> in <module>
----> 1 unflatten({1: ('a', 'b'), 2: ('a', 'b')}, inverse=True)

~/projects/flatten-dict/flatten_dict/flatten_dict.py in unflatten(d, splitter, inverse)
    122             flat_key, value = value, flat_key
    123         key_tuple = splitter(flat_key)
--> 124         nested_set_dict(unflattened_dict, key_tuple, value)
    125 
    126     return unflattened_dict

~/projects/flatten-dict/flatten_dict/flatten_dict.py in nested_set_dict(d, keys, value)
     91         return
     92     d = d.setdefault(key, {})
---> 93     nested_set_dict(d, keys[1:], value)
     94 
     95 

~/projects/flatten-dict/flatten_dict/flatten_dict.py in nested_set_dict(d, keys, value)
     87     if len(keys) == 1:
     88         if key in d:
---> 89             raise ValueError("duplicated key '{}'".format(key))
     90         d[key] = value
     91         return

ValueError: duplicated key 'b'

Expected error:

ValueError: duplicated key ('a', 'b')
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