Python basics === monkeytype can automatically add annotation modules !, Pythonmonkeytype

Source: Internet
Author: User

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 #

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.