Fix casting to int silently failing

This commit is contained in:
croneter 2019-06-12 11:24:56 +02:00
parent a46cb731cf
commit d96ac192d1

View file

@ -292,7 +292,16 @@ def cast(func, value):
return value return value
else: else:
return value.encode('utf-8') return value.encode('utf-8')
elif func in (int, float): elif func == int:
try:
return func(value)
except ValueError:
try:
# Converting e.g. '8.0' fails; need to convert to float first
return int(float(value))
except ValueError:
return float('nan')
elif func == float:
try: try:
return func(value) return func(value)
except ValueError: except ValueError: