Google produced the Python code analyzer static type: Pytype

Pytype check and infer the type Python code - no type annotations. Pytype can:

  • Use lint to check pure Python code, markup common errors, spelling errors, incorrect function calls, such as property, and much more, it can even across files.
  • Strengthen type annotations provided by the user. Although the notes for pytype is optional, but when the presence of the annotation, it checks and apply them.
  • Type annotations to generate a separate file ( "File PYI"), a merge-pyi may be used provided the tool itself which is incorporated back into the Python source code.

Pytype is a static analyzer, which means that it checks the code it does not perform.

Google's thousands of projects rely pytype to maintain its good Python code and type of error.

For more information, please see the user guide or FAQ.

Getting Started

To quickly begin a file or directory type checking, you just run the following command, replacing file_or_directory with your input:

Google produced the Python code analyzer static type: Pytype

 

To set the entire package pytype, add the following to the parent directory setup.cfg package file, replace package_name with the package name:

Google produced the Python code analyzer static type: Pytype

 

Now, you can run the command without parameters pytype to check the type of package. Adding pytype to your automated testing is also very easy; pytype example of GitHub project see running on Travis.

Finally, pytype generated file containing type information inferred located .pytype / pyi in default. You can use this information to the appropriate source file type annotations, module.py replaced with import file path:

Google produced the Python code analyzer static type: Pytype

 

demand

You need a Python 2.7 or 3.5+ interpreter to run pytype, also you need to set a $ PATH in with the same version of Python code Python interpreter analyzed.

Platform Support:

  • Pytype currently developed and tested on Linux, Linux is mainly supported platforms.
  • Installation requires OSX later and Xcode v8 version 10.7 or later, or on MacOSX.
  • Currently does not support windows.

installation

Pytype can be installed by a pip. Note that the installation process requires the use of wheel and setuptools. (If you work in virtualenv, both packages should already exist.)

Google produced the Python code analyzer static type: Pytype

 

Or be installed from the source on GitHub:

Google produced the Python code analyzer static type: Pytype

 

Instead of using --recurse-submodules installation parameters, you can also install using the following command in pytype directory:

Google produced the Python code analyzer static type: Pytype

 

usage

Google produced the Python code analyzer static type: Pytype

 

Common options:

  • -V, - Python-Version: Python version of the object code (major.minor). The default is 3.6.
  • -o, - output: All output directory to save pytype, including .pyi generated files. The default is .pytype.
  • -d, - disable. List of names separated by commas error to be ignored. Details pytype incorrect names in this document. The default is empty.

For a complete list of options, run pytype --help.

In addition to the above, you can also set the $ TYPESHED_HOME directly run pytype command uses typeshed install substitute its own binding copy.

Profiles

For convenience, you can configure your pytype saved in a file. A profile is a with [pytype] INI- pattern portion; if no explicit profile, pytype will traverse up from the current directory to find [pytype] Part setup.cfg a file.

We start with a sample configuration file is generated:

Google produced the Python code analyzer static type: Pytype

 

Now we customize according to local settings file, leaving only the parts you need. It may be a relative path to the configuration file, if you want the configuration file as part of the project inspection, which is very useful.

For example, suppose you have the following directory structure, and you want to analyze packet ~ / repo1 / foo, it depends on the package ~ / repo2 / bar:

Google produced the Python code analyzer static type: Pytype

 

The following is a good profile is provided, it indicates the pytype ~ / repo1 / foo as Python 3.6 type checking code, find the package in ~ / repo1 and ~ / repo2 and ignore the error property. Note that the path to the packet not including the packet itself.

Google produced the Python code analyzer static type: Pytype

 

We may find it necessary to add damage by running pytype dependency checker ~ / repo2 to pythonpath in:

Google produced the Python code analyzer static type: Pytype

 

Subtools

In addition to pytype itself, Pytype also comes with three scripts:

  • merge-pyi, .pyi file type information for the file will be merged into Python.
  • pytd, a .pyi file parser.
  • pytype-single, pytype developers debugging tools, used to analyze a single Python file, and the file assumed to have been generated for all dependencies .pyi Python file.

Product Roadmap

• Support for Windows Systems

license

 

Guess you like

Origin blog.csdn.net/java276582434/article/details/90813221