If a function can return None
, shouldn't the type annotation use NoneType
?
For example, shouldn't we use this:
from types import NoneType
def my_function(num: int) -> int | NoneType:
if num > 0:
return num
return None
instead of:
def my_function(num: int) -> int | None:
if num > 0:
return num
return None
?