Skip to content

Commit

Permalink
remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
Keegan Cordeiro committed Mar 27, 2024
1 parent e2bc670 commit 1e3f7cf
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions predicthq/endpoints/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ def _to_url_params(key_list_mapping, glue=".", separator=",", parent_key=""):
"""
params = {}
for key, value in key_list_mapping.items():
current_key = f"{parent_key}{glue}{key}" if parent_key else key
for v in value:
if isinstance(v, dict):
params.update(_to_url_params(v, glue, separator, f"{parent_key}{glue}{key}" if parent_key else key))
params.update(_to_url_params(v, glue, separator, current_key))
elif isinstance(v, list):
params.update({f"{parent_key}{glue}{key}" if parent_key else key: separator.join(map(str, v))})
params.update({current_key: separator.join(map(str, v))})
elif isinstance(v, bool):
params.update({f"{parent_key}{glue}{key}" if parent_key else key: 1 if v else 0})
params.update({current_key: 1 if v else 0})
else:
params.update({f"{parent_key}{glue}{key}" if parent_key else key: v})
params.update({current_key: v})
return params


Expand Down

0 comments on commit 1e3f7cf

Please sign in to comment.