Commit 715123fe authored by Alexander Povel's avatar Alexander Povel

Introduce a default return value on conversion failure

parent f288ba18
......@@ -44,14 +44,16 @@ class RoughPoint(Point):
def convert_and_round(numeric_string: str, n_digits: int) -> float:
def convert_and_round(numeric_string: str, n_digits: int, default=0) -> float:
result = round(float(numeric_string), ndigits=n_digits)
except ( # Treat these exceptions equally
ValueError, # Cannot convert empty string to float
TypeError, # Cannot convert None to float
result = None
# Returning a default of 0 for a failed conversion is maybe a bad idea,
# since there might be deeper issues getting covered up.
result = default
return result
def __new__(cls, latitude, longitude, altitude=None, altitude_factor=1, n_digits=3):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment