Skip to content

Commit

Permalink
🩹 Fix non-str object being casted to json
Browse files Browse the repository at this point in the history
  • Loading branch information
pwwang committed Oct 28, 2021
1 parent 1391ae9 commit 1e870e7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pyparam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,13 @@ def cast_to(value: Any, to_type: Union[str, bool]) -> Any:
"Expecting one of [true, TRUE, True, 1, false, FALSE, False, 0]"
)

if to_type in ("path", "py", "json"):
return {"path": Path, "py": ast.literal_eval, "json": json.loads}[
if to_type == "json":
if isinstance(value, str):
return json.loads(value)
return json.loads(json.dumps(value))

if to_type in ("path", "py"):
return {"path": Path, "py": ast.literal_eval}[
to_type # type: ignore
](str(value))
if to_type in (None, "auto"):
Expand Down

0 comments on commit 1e870e7

Please sign in to comment.