python基础===monkeytype可以自动添加注释的模块!

monkeytype 一个可以自动添加注释的模块!

 

先要下载:

pip install monkeytype

 

以官网的sample code为例

#moudle.py

def add(a, b):
    return a + b

这个test.py的文件会调用add()方法

#test.py

from
module import add print(add(1, 2))

我们在cmd窗口执行如下命令:

monkeytype run test.py

程序执行完毕,可以看到返回了3

ok!重点来了,我们发现多了一个monkeytype.sqlite3文件。

官网解释是这样的:

By default this will dump call traces into a sqlite database in the file monkeytype.sqlite3 in the current working directory. You can then use the monkeytype command to generate a stub file for a module, or apply the type annotations directly to your code.

在cmd下执行命令:

monkeytype stub some.module

可以清楚的看到对a 和 b ,以及add方法的注释

应用注释到代码中:

monkeytype apply some.module

再看module.py文件:

代码已经自动打上注释了。

 

详细操作指南,参考:

http://monkeytype.readthedocs.io/en/latest/index.html#

 

 

 

 

 

 

转载于:https://www.cnblogs.com/botoo/p/8303559.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值