Skip to content

__setitem__ does not work on a dictionary of lists for FlatterDict #51

Description

@darioisola

The following

import flatdict

fdoc = flatdict.FlatterDict({'a': [3, 4]})
fdoc['a:0'] = 1

should set the first element of the list a but it raises the an error

Traceback (most recent call last):
  File "/home/dario/miniconda3/envs/rotore_for_commit_devel/lib/python3.8/site-packages/flatdict.py", line 411, in __setitem__
    k, cck = ck.split(self._delimiter, 1)
ValueError: not enough values to unpack (expected 2, got 1)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/dario/miniconda3/envs/rotore_for_commit_devel/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3397, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-cf8840d6b1c9>", line 1, in <cell line: 1>
    runfile('/home/dario/Codes/rotor_design_for_commit/activities/tiltrotor_tip/submit.py', wdir='/home/dario/Codes/rotor_design_for_commit/activities/tiltrotor_tip')
  File "/home/dario/Software/pycharm-2021.2.3/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 198, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/home/dario/Software/pycharm-2021.2.3/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/dario/Codes/rotor_design_for_commit/activities/tiltrotor_tip/submit.py", line 23, in <module>
    fdoc['a:0'] = 1
  File "/home/dario/miniconda3/envs/rotore_for_commit_devel/lib/python3.8/site-packages/flatdict.py", line 414, in __setitem__
    raise TypeError(
TypeError: Assignment to invalid type for key a:0

which I can be fixed in various ways. I assume this is not the intended behavior.

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