"""Contain logic for checking average files""" import re from typing import Union from .errors import InvalidValue from .errors import InvalidCellValue def valid_value(val): """Checks whether `val` is a valid value for averages""" if re.search(r"^[0-9]+\.[0-9]{3}$", val): return float(val) raise InvalidCellValue( f"Invalid value '{val}'. " "Expected string representing a number with exactly three decimal " "places.") def invalid_value(line_number: int, column_number: int, val: str) -> Union[ InvalidValue, None]: if re.search(r"^[0-9]+\.[0-9]{3}$", val): return None return InvalidValue( line_number, column_number, val, ( f"Invalid value '{val}'. " "Expected string representing a number with exactly three decimal " "places."))