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

Clarification on ambiguous as_dict() #47

Open devleaks opened 2 years ago

devleaks commented 2 years ago

Hello,

I apologize if I misunderstand the documentation but what is the purpose of the as_dict() help function?

import flatdict

>>> c = flatdict.FlatDict({"a": {"b":1}})
>>> print(type(c), c)
<class 'flatdict.FlatDict'> {'a:b': 1}

>>> d = flatdict.FlatDict({"a": {"b":1}}).as_dict()
>>> print(type(d), d)
<class 'dict'> {'a': {'b': 1}}

>>> e = dict(flatdict.FlatDict({"a": {"b":1}}))
>>> print(type(e), e)
<class 'dict'> {'a:b': 1}

I understood that as_dict() returns the result (the flattened dict) as a standard python dictionary rather than a flatdict.FlatDict object. It is not the case. Can you please clarify, and lift the ambiguity in the doc. Thank you.

Otherwise, this is a very handy package. Thank you.

P.

PS: Calling with .as_dict() takes a lot of time on larger dictionaries.