Skip to main content

automatically add annotations to untyped python code!

Project description

build status

auto-type-annotate

automatically add annotations to untyped python code!

installation

pip install auto-type-annotate

usage

this tool is intented to help you automatically add annotations while gradually typing a code base!

there's a few pre-requisites you'll need to do in order to use the tool successfully

first you'll need to make your codebase pass mypy with the following settings enabled:

  • check_untyped_defs = true: this is needed to analyze types in functions we'd like to automatically type
  • local_partial_types = true: this is a setting forced by dmypy -- which we'll be using to generate typing suggestions

you can check whether you're "ready" to use this by running the following:

dmypy stop
dmypy run

it should look something like:

$ dmypy stop
Daemon stopped
$ dmypy run
Daemon started
Success: no issues found in 6839 source files

once that passes -- and dmypy is still running: use the tool on whatever files you'd like to improve!

for instance after:

auto-type-annotate \
    --application-directories .:src \
    src/sentry/api/authentication.py
$ git diff
diff --git a/src/sentry/api/authentication.py b/src/sentry/api/authentication.py
index ec0526b9f62..ac797d136f5 100644
--- a/src/sentry/api/authentication.py
+++ b/src/sentry/api/authentication.py
@@ -86,7 +86,7 @@ class AuthenticationSiloLimit(SiloLimit):
         )


-def is_internal_relay(request, public_key):
+def is_internal_relay(request: Request, public_key: str) -> bool:
     """
     Checks if the relay is trusted (authorized for all project configs)
     """
@@ -99,7 +99,7 @@ def is_internal_relay(request, public_key):
     return is_internal_ip(request)


-def is_static_relay(request):
+def is_static_relay(request: Request) -> bool:
     """
     Checks if the request comes from a statically configured relay

@@ -141,7 +141,7 @@ def relay_from_id(request: Request, relay_id: str) -> tuple[Relay | None, bool]:
             return None, False  # no Relay found

why not pyannotate?

:'(

$ pyannotate --help
Traceback (most recent call last):
  File ".venv/bin/pyannotate", line 5, in <module>
    from pyannotate_tools.annotations.__main__ import main
  File ".venv/lib/python3.13/site-packages/pyannotate_tools/annotations/__main__.py", line 9, in <module>
    from lib2to3.main import StdoutRefactoringTool
ModuleNotFoundError: No module named 'lib2to3'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

auto_type_annotate-1.1.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

auto_type_annotate-1.1.0-py2.py3-none-any.whl (10.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file auto_type_annotate-1.1.0.tar.gz.

File metadata

  • Download URL: auto_type_annotate-1.1.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for auto_type_annotate-1.1.0.tar.gz
Algorithm Hash digest
SHA256 9e654acb2626cdd5cb8e6a5727bdba20d54cfd6e0cb6339e5831ed849267de25
MD5 02720bf99e37535c7839c93364cf19fe
BLAKE2b-256 fef8f47f734f3c0e644e30bf95c7313c8ca88574f98eeee48d3d9a8be774e00d

See more details on using hashes here.

File details

Details for the file auto_type_annotate-1.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for auto_type_annotate-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f6d3a50f6d38bd2ec747771bc216d2f6f293f7a42ecb6cab1ee6fe7c1ee10b7d
MD5 fb300afa3abee73b8d78bdbb79bee1f8
BLAKE2b-256 f44c53ae634f372410bd7e99ee1a108c98deb289143459c0ce445f7d4f6f0bfc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page