def some_func(number: int) -> List[int]:
if number < 1:
raise ValueError("number must be greater than or equal to zero")
return [i for i in range(number)]
def some_func(number: int) -> Optional[List[int]]:
if number < 1:
raise ValueError("number must be greater than or equal to zero")
return [i for i in range(number)]
I implemented some function which has construct like above. This raise Value Exception in some condition. But in normal case, It returns some value. In this situation, Should I use Optional Type hint or not? ->
symbol is represent of return type. I think that raise
is different with return
. So, return type must be related only return
.
Which code do you think is correct?