in azure_functions_worker/bindings/nullable_converters.py [0:0]
def to_nullable_double(nullable: Optional[Union[str, int, float]],
property_name: str) -> \
Optional[protos.NullableDouble]:
"""Converts int or float or str that parses to a number to an
'NullableDouble' to be sent through the RPC layer. Input that is not a
valid number but is also not null or undefined logs a function app level
warning.
:param nullable Input to be converted to an NullableDouble if it is a
valid number
:param property_name The name of the property that the caller will
assign the output to. Used for debugging.
"""
if isinstance(nullable, int) or isinstance(nullable, float):
return protos.NullableDouble(value=nullable)
elif isinstance(nullable, str):
if len(nullable) == 0:
return None
try:
return protos.NullableDouble(value=float(nullable))
except Exception:
raise TypeError(
f"Cannot parse value {nullable} of '{property_name}' to "
f"float.")
if nullable is not None:
raise TypeError(
f"A 'int' or 'float'"
f" type was expected instead of a '{type(nullable)}' "
f"type. Cannot parse value {nullable} of '{property_name}'.")
return None