Skip to content

Commit

Permalink
wraps(strict=True) now accept strings as arguments in the wrapper fun…
Browse files Browse the repository at this point in the history
…ction

Closes #711, #723
  • Loading branch information
hgrecco committed Dec 28, 2019
1 parent d7b864d commit 2d48e6b
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pint/registry_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,20 @@ def _converter(ureg, values, strict):
)
else:
if strict:
raise ValueError(
"A wrapped function using strict=True requires "
"quantity for all arguments with not None units. "
"(error found for {}, {})".format(
args_as_uc[ndx][0], new_values[ndx]
if isinstance(values[ndx], str):
# if the value is a string, we try to parse it
tmp_value = ureg.parse_expression(values[ndx])
new_values[ndx] = ureg._convert(
tmp_value._magnitude, tmp_value._units, args_as_uc[ndx][0]
)
else:
raise ValueError(
"A wrapped function using strict=True requires "
"quantity or a string for all arguments with not None units. "
"(error found for {}, {})".format(
args_as_uc[ndx][0], new_values[ndx]
)
)
)

return new_values, values_by_name

Expand Down

0 comments on commit 2d48e6b

Please sign in to comment.