Let's say I have the function:
def foo(integer: int) -> int:
if integer < 0:
raise ValueError("The integer must be positive")
return integer * 2
If I look at the signature for this function, it will only tell me that it takes an int
and returns an int
.
However, it would be really nice to know that it also has the chance of raising a ValueError
in case I need to catch that.
Is there any way to put what errors a function raises into the types, or is this just something that should go into the docstring?
Unfortunately, no. Docstrings would be a good practice.