Ad

MonkeyType: Static type annotation inference

MonkeyType automatically generates static type annotations by analyzing runtime types, streamlining code documentation and static analysis.
Screenshot of Instagram/MonkeyType homepage

MonkeyType collects runtime types of function arguments and return values to automatically generate type annotations for Python code. It addresses the need for easily adding accurate type information to Python programs, improving code readability and enabling static analysis with type checkers like mypy. MonkeyType works by instrumenting Python's runtime to record type information.

MonkeyType generates type stubs and can directly apply type annotations to code, simplifying the process of adding type information. It's particularly effective in situations where runtime types are not explicitly specified. The library provides a straightforward command-line interface for generating and applying these types.

  • Runtime Type Inference: Automatically determines types during program execution.
  • Stub File Generation: Creates stub files containing type annotations.
  • Code Annotation Application: Applies type annotations directly to Python code.
  • Python 3.9+ Support: Requires Python 3.9 or higher for operation.
  • libcst Dependency: Relies on the libcst library for code modification.
  • Informative Drafts: Generates initial type annotations for developers to refine.
  • Easy Integration: Simple command-line usage for type inference.

MonkeyType is an actively maintained project with a history of releases and ongoing development. Recent commits and issue activity indicate continued support and improvements. Comprehensive documentation and a community presence contribute to its reliability. The project aims to provide a reliable mechanism for automating type annotation generation.

Developers seeking to improve code clarity and enable static analysis in Python can benefit from MonkeyType. It's particularly useful for projects where adding type annotations manually is tedious or error-prone. By automatically generating type information, MonkeyType reduces development time and enhances code maintainability, providing a valuable alternative to manual annotation or relying solely on docstrings.

Languages:
Summarize:
Share:
Stars
5,000
Forks
207
Issues
78
Created
9 years ago
Commit
6 months ago
License
OTHER
Archived
No
Updated 15 days ago

Similar Repositories