My goal is to understand how Python handle type. I found out that Python have similar way to describe type like TypeScript. However, when I tried to misuse the function e.g Speak(1.0)
. The IDE nor the python main.py
will panic. It will still invoke the function although the function arg is a float.
main.py
def Speak(input: str | int) -> TypeError | None:
if type(input) != str and type(input) != int:
return TypeError("type not supported")
if type(input) == str:
print("str")
return
elif type(input) == int:
print("int")
return
Speak(1.0)