JelleZijlstra / autotyping

Automatically add simple type annotations to your code
215 stars 18 forks source link
mypy python typing

When I refactor code I often find myself tediously adding type annotations that are obvious from context: functions that don't return anything, boolean flags, etcetera. That's where autotyping comes in: it automatically adds those types and inserts the right annotations.

Usage

Here's how to use it:

By default it does nothing; you have to add flags to make it do more transformations. The following are supported:

There are two shortcut flags to enable multiple transformations at once:

LibCST

Autotyping is built as a LibCST codemod; see the LibCST documentation for more information on how to use codemods.

If you wish to run things through the libcst.tool interface, you can do this like so:

Limitations

Autotyping is intended to be a simple tool that uses heuristics to find annotations that would be tedious to add by hand. The heuristics may fail, and after you run autotyping you should run a type checker to verify that the types it added are correct.

Known limitations:

Changelog

24.3.0 (March 25, 2024)

23.3.0 (March 3, 2023)

23.2.0 (February 3, 2023)

22.9.0 (September 5, 2022)

21.12.0 (December 21, 2021)