python - 使用键入 类 手动执行键入约束
python - Manually execute typing constraints using typing classes
我想验证一些参数的类型,最好使用 typing
定义
例如:
from typing import List, Dict
def func(param1, param2):
assert param1 is of type Dict[str, int] # How can this be done?
assert param2 is of type List[Any] # How can this be done?
非复杂类型很容易。 assert isinstance(param1, str)
问题明显简化了,说清楚了
我想验证一些参数的类型,最好使用 typing
定义
例如:
from typing import List, Dict
def func(param1, param2):
assert param1 is of type Dict[str, int] # How can this be done?
assert param2 is of type List[Any] # How can this be done?
非复杂类型很容易。 assert isinstance(param1, str)
问题明显简化了,说清楚了