收藏    我在用   0 人在用
 -  null

A system for Python that generates static type annotations by collecting runtime types

 GitHub     下载     同步

43    1928    84    over 1 year前


MonkeyType collects runtime types of function arguments and return values, and
can automatically generate stub files or even add draft type annotations
directly to your Python code based on the types collected at runtime.


Run a script under call-trace logging of functions and methods in all imported

$ monkeytype run

Or enable call-trace logging for a block of code::

import monkeytype

with monkeytype.trace():

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::

$ monkeytype stub some.module
$ monkeytype apply some.module


MonkeyType requires Python 3.6+ and the retype_ library (for applying type
stubs to code files). It generates only Python 3 type annotations (no type


Install MonkeyType with pip_::

pip install MonkeyType

How MonkeyType works

MonkeyType uses the sys.setprofile_ hook provided by Python to interpose on
function calls, function returns, and generator yields, and record the types of
arguments / return values / yield values.

It generates stub files_ based on that data, and can use retype_ to apply those
stub files directly to your code.

.. _pip:
.. _retype:
.. _sys.setprofile:
.. _stub files:

.. end-here

See the full documentation_ for details.

.. _the full documentation:


MonkeyType is BSD licensed. We also provide an additional patent grant.

No Reply at the moment.
需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up