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

栏目: Python · 发布时间: 8年前

内容简介: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

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

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

应用注释到代码中:

monkeytype apply some.module

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

再看module.py文件:

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

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

详细操作指南,参考:

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


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Hacker's Delight

Hacker's Delight

Henry S. Warren Jr. / Addison-Wesley / 2002-7-27 / USD 59.99

A collection useful programming advice the author has collected over the years; small algorithms that make the programmer's task easier. * At long last, proven short-cuts to mastering difficult aspec......一起来看看 《Hacker's Delight》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

在线进制转换器
在线进制转换器

各进制数互转换器

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具