flatdict
flatdict copied to clipboard
Assignment to invalid type
I try to convert all values of a FlatterDict to strings. The email field caused an exception.
See below
data = {
"x": "12",
"other": "MLL",
"channel": 33,
"language": "EN",
"email": [
"[email protected]"
]
}
flat = flatdict.FlatterDict(data)
for k in flat.keys():
flat[k] = str(flat[k])
Error:
File "C:\dev\tools\python371\lib\site-packages\flatdict.py", line 416, in __setitem__
pk, self._delimiter, ck))
TypeError: Assignment to invalid type for key email:0
I'm also encountering this issue, it seems to happen only for list original types
Specifically this code: https://github.com/gmr/flatdict/blob/f86186671944e39ae194b49c5f444d69ffa37424/flatdict.py#L408-L418 L411 will fail because it is trying to split e.g.,
# key = "email:0" ->
a, b = "0".split(':', 1)
It seems like there either needs to be an extra check for a delimiter or not do the second split.