mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-30 21:54:29 -04:00
Add a docstring & tests for _flatten_dict. (#14981)
This commit is contained in:
parent
52700a0bcf
commit
f0cae26d58
3 changed files with 49 additions and 1 deletions
|
@ -473,6 +473,29 @@ def _flatten_dict(
|
|||
prefix: Optional[List[str]] = None,
|
||||
result: Optional[Dict[str, str]] = None,
|
||||
) -> Dict[str, str]:
|
||||
"""
|
||||
Given a JSON dictionary (or event) which might contain sub dictionaries,
|
||||
flatten it into a single layer dictionary by combining the keys & sub-keys.
|
||||
|
||||
Any (non-dictionary), non-string value is dropped.
|
||||
|
||||
Transforms:
|
||||
|
||||
{"foo": {"bar": "test"}}
|
||||
|
||||
To:
|
||||
|
||||
{"foo.bar": "test"}
|
||||
|
||||
Args:
|
||||
d: The event or content to continue flattening.
|
||||
room_version: The room version object.
|
||||
prefix: The key prefix (from outer dictionaries).
|
||||
result: The result to mutate.
|
||||
|
||||
Returns:
|
||||
The resulting dictionary.
|
||||
"""
|
||||
if prefix is None:
|
||||
prefix = []
|
||||
if result is None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue