homework_checker/core/tools.py
def convert_to(
    output_type: str, value: Any
) -> Union[Tuple[Optional[str], str], Tuple[Optional[float], str]]:
    """Convert the value to a specified type."""
    if not value:
        return None, "No value. Cannot convert {} to '{}'.".format(value, output_type)
    try:
        if output_type == OutputTags.STRING:
            return str(value).strip(), "OK"
        if output_type == OutputTags.NUMBER:
            return float(value), "OK"
    except ValueError as error:
        log.error("Exception: %s.", error)
        return None, str(error)
    return None, "Unknown output type {}. Cannot convert.".format(output_type)
Convert the value to a specified type.
Convert the value to a specified type.
Convert the value to a specified type .
def convert_to(
    output_type: str, value: Any
) -> Union[Tuple[Optional[str], str], Tuple[Optional[float], str]]:
    if not value:
        return None, "No value. Cannot convert {} to '{}'.".format(value, output_type)
    try:
        if output_type == OutputTags.STRING:
            return str(value).strip(), "OK"
        if output_type == OutputTags.NUMBER:
            return float(value), "OK"
    except ValueError as error:
        log.error("Exception: %s.", error)
        return None, str(error)
    return None, "Unknown output type {}. Cannot convert.".format(output_type)
def convert_to ( output_type : str , value : Any ) -> Union [ Tuple [ Optional [ str ] , str ] , Tuple [ Optional [ float ] , str ] ] : if not value : return None , "No value. Cannot convert {} to '{}'." . format ( value , output_type ) try : if output_type == OutputTags . STRING : return str ( value ) . strip ( ) , "OK" if output_type == OutputTags . NUMBER : return float ( value ) , "OK" except ValueError as error : log . error ( "Exception: %s." , error ) return None , str ( error ) return None , "Unknown output type {}. Cannot convert." . format ( output_type )
Convert the value to a specified type.
Convert the value to a specified type .
"""Convert the value to a specified type."""
output_type
str
value
Any