I used the object None, then error doesn't occur but the readability isn't good not to differentiate the type None and the default value None as shown below:
*Memo:
# Cannot differenciate
# ↓↓↓↓ ↓↓↓↓
def func(name: str | None = None) -> str:
return f'My name is {name}.'
So, I used the type NoneType to improve the readability to differentiate the type NoneType and the default value None but the error occurs as shown below:
from types import NoneType
# Can differenciate
# ↓↓↓↓↓↓↓↓ ↓↓↓↓
def func(name: str | NoneType = None) -> str:
return f'My name is {x}.'
$ mypy test.py
test.py:5: error: NoneType should not be used as a type, please use None instead [valid-type]
Found 1 error in 1 file (checked 1 source file)
Actually, it's not reasonable that the object None works but the type NoneType doesn't work.
I used the object None, then error doesn't occur but the readability isn't good not to differentiate the type
Noneand the default valueNoneas shown below:*Memo:
So, I used the type NoneType to improve the readability to differentiate the type
NoneTypeand the default valueNonebut the error occurs as shown below:Actually, it's not reasonable that the object
Noneworks but the typeNoneTypedoesn't work.