def require_int(value: Optional[Union[SupportsInt, str, bytes]], allow_none: bool=False) -> Any:
"""Make sure a value is an int.
Used when dealing with http input data.
"""
if value is None and allow_none:
return value
value = cast(Union[SupportsInt, str, bytes], value)
try:
value = int(value)
except (ValueError, TypeError):
raise InvalidData('value was %s(%s), expected list' % (type(value), value))
return value
评论列表
文章目录