Python basics === monkeytype can automatically add annotation modules !, Pythonmonkeytype
Monkeytype: a module that can automatically add comments!
Download:
Pip install monkeytype
Take the sample code on the official website as an example.
#moudle.pydef add(a, b): return a + b
The test. py file will call the add () method.
#test.py
from module import addprint(add(1, 2))
Run the following command in the cmd window:
Monkeytype run test. py
After the program is executed, 3 is returned.
OK! The point is, we find that there is an additional monkeytype. sqlite3 file.
The official website explains this:
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.
Run the following command in cmd:
Monkeytype stub some. module
You can clearly see the annotations for a, B, and the add method.
Comments the application to the Code:
Monkeytype apply some. module
Check the module. py file again:
The code is automatically annotated.
For detailed instructions, refer:
Http://monkeytype.readthedocs.io/en/latest/index.html #