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,21 +88,25 @@ def parse_number_and_unit(
|
|||||||
elif isinstance(inp, NumberAndUnit):
|
elif isinstance(inp, NumberAndUnit):
|
||||||
return inp
|
return inp
|
||||||
elif isinstance(inp, float) or isinstance(inp, int):
|
elif isinstance(inp, float) or isinstance(inp, int):
|
||||||
return NumberAndUnit(float(inp), default_unit)
|
return NumberAndUnit(inp, default_unit)
|
||||||
elif isinstance(inp, str):
|
elif isinstance(inp, str):
|
||||||
if " " in inp:
|
if " " in inp:
|
||||||
number, unit = inp.split(" ", 1)
|
num_str, unit = inp.split(" ", 1)
|
||||||
else:
|
else:
|
||||||
number, unit = inp, default_unit
|
num_str, unit = inp, default_unit
|
||||||
|
|
||||||
try:
|
try:
|
||||||
number = float(number)
|
number = int(num_str)
|
||||||
except ValueError:
|
except ValueError: # maybe it is a float?
|
||||||
raise Exception(
|
try:
|
||||||
f"{inp} is not a valid number and unit.\n"
|
number = float(num_str)
|
||||||
"It must be a number, or a number and unit separated by a space."
|
except ValueError: # neither float nor int
|
||||||
)
|
raise Exception(
|
||||||
else:
|
f"{inp} is not a valid number and unit.\n"
|
||||||
return NumberAndUnit(number, unit)
|
"It must be a number, or a number and unit separated by a space."
|
||||||
|
)
|
||||||
|
|
||||||
|
return NumberAndUnit(number, unit)
|
||||||
|
|
||||||
|
|
||||||
def int2tuple(inp):
|
def int2tuple(inp):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user