gmr / flatdict

Python module for interacting with nested dicts as a single level dict with delimited keys.
https://flatdict.readthedocs.io
BSD 3-Clause "New" or "Revised" License
112 stars 32 forks source link

Flatdict() doesn’t support deeply nested dictionaries #2

Closed bfontaine closed 5 years ago

bfontaine commented 9 years ago

Test:

import flatdict
d = {"foo": 42}
for _ in range(1000):
    d = {"1": d}  # create a 1000-levels nested dictionary
f = flatdict.FlatDict(d)

gives:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/private/tmp/toto/venv/lib/python2.7/site-packages/flatdict.py", line 27, in __init__
    self.__setitem__(key, value[key])
  File "/private/tmp/toto/venv/lib/python2.7/site-packages/flatdict.py", line 70, in __setitem__
    value = FlatDict(value, self._delimiter)
  File "/private/tmp/toto/venv/lib/python2.7/site-packages/flatdict.py", line 27, in __init__
    self.__setitem__(key, value[key])
  [… truncated …]
  File "/private/tmp/toto/venv/lib/python2.7/site-packages/flatdict.py", line 22, in __init__
    super(FlatDict, self).__init__()
RuntimeError: maximum recursion depth exceeded while calling a Python object

Tested with Flatdict 1.1.1 and Python 2.7.9.

If this can help you I recently released a similar library, flatkeys, and I worked around the maximum recursion depth limit by removing any recursion and using a stack instead.

gmr commented 9 years ago

Thanks, that is an interesting use case I'd not thought of. I'll address this when I come up from air from a few other projects.

gmr commented 5 years ago

Seems like it's an edge case for flatdict at this point, given no other reports or PRs to fix. Thanks for the report, but closing at this time.