Skip to content

Commit

Permalink
refactor: add a separator param to generate_substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
sujuka99 committed Nov 3, 2023
1 parent 605c2fe commit deadfd7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions kpops/utils/dict_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def flatten_mapping(
if prefix:
key = prefix + separator + key
if isinstance(value, Mapping):
nested_mapping = flatten_mapping(value, key)
nested_mapping = flatten_mapping(value, key, separator)
top = update_nested_pair(top, nested_mapping)
else:
top[key] = value
Expand All @@ -77,6 +77,7 @@ def generate_substitution(
input: dict,
prefix: str | None = None,
existing_substitution: dict | None = None,
separator: str | None = None,
) -> dict:
"""Generate a complete substitution dict from a given dict.
Expand All @@ -88,4 +89,10 @@ def generate_substitution(
:param substitution: existing substitution to include
:returns: Substitution dict of all variables related to the model.
"""
return update_nested(existing_substitution or {}, flatten_mapping(input, prefix))
if separator is None:
return update_nested(
existing_substitution or {}, flatten_mapping(input, prefix)
)
return update_nested(
existing_substitution or {}, flatten_mapping(input, prefix, separator)
)

0 comments on commit deadfd7

Please sign in to comment.