Remove unnecessary casting of int to float
https://github.com/wireviz/WireViz/pull/251#discussion_r1359000766
This commit is contained in:
parent
9e72905895
commit
cc18c62f3e
@ -88,20 +88,24 @@ def parse_number_and_unit(
|
||||
elif isinstance(inp, NumberAndUnit):
|
||||
return inp
|
||||
elif isinstance(inp, float) or isinstance(inp, int):
|
||||
return NumberAndUnit(float(inp), default_unit)
|
||||
return NumberAndUnit(inp, default_unit)
|
||||
elif isinstance(inp, str):
|
||||
if " " in inp:
|
||||
number, unit = inp.split(" ", 1)
|
||||
num_str, unit = inp.split(" ", 1)
|
||||
else:
|
||||
number, unit = inp, default_unit
|
||||
num_str, unit = inp, default_unit
|
||||
|
||||
try:
|
||||
number = float(number)
|
||||
except ValueError:
|
||||
number = int(num_str)
|
||||
except ValueError: # maybe it is a float?
|
||||
try:
|
||||
number = float(num_str)
|
||||
except ValueError: # neither float nor int
|
||||
raise Exception(
|
||||
f"{inp} is not a valid number and unit.\n"
|
||||
"It must be a number, or a number and unit separated by a space."
|
||||
)
|
||||
else:
|
||||
|
||||
return NumberAndUnit(number, unit)
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user