The Standard Library module typing introduces many useful types, which is very useful for type hinting. For instance, one can define the type of the elements expected of a list. The code below fails:
from type_valid import type_valid
from typing import List
@type_valid
def foobar(arg: List[float]) -> bool:
return True
my_list = [1.1, 3.2, 7.2]
print(foobar(my_list))
While using a regular list type instead of List[float] doesn't:
from type_valid import type_valid
@type_valid
def foobar(arg: list) -> bool:
return True
my_list = [1.1, 3.2, 7.2]
print(foobar(my_list))
It's worth noting that tools such as mypy support listings.
The Standard Library module
typingintroduces many useful types, which is very useful for type hinting. For instance, one can define the type of the elements expected of a list. The code below fails:While using a regular
listtype instead ofList[float]doesn't:It's worth noting that tools such as
mypysupportlistings.