函数签名的动态类型检查器
strong的Python项目详细描述
在
函数签名的强动态类型检测器
Strong通过为函数签名提供动态类型检查来支持内置typing
包。在
安装:
只需使用:
pip install strong
文件:
文档以here为宿主。在
示例:
假设有一个函数接受两个输入a
和{
这个包提供了一些工具来简化检查输入参数类型的任务。在
>>>fromstrong.core.decoratorsimportassert_correct_typing>>>@assert_correct_typing>>>deff(a:int,b:int)->int:>>>returna+b>>>x=f(1,2)# O.K.>>>y=f(1,'2')# K.O.AssertionError:Functionfdefinedin"<function_file>",line3Argument`b`doesnotmatchtyping:'2'isnotaninstanceof<class'int'>>>>fromstrong.core.decoratorsimportmeasure_overhead>>>importnumpyasnp>>>@measure_overhead(assert_correct_typing)>>>defg(a:int,b:int)->np.ndarray:returnnp.random.rand(a,b)>>>g(100,100)1.0687804670719938# Ratio between time taken with @assert_correct_typing and without
- 项目
标签: