Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MonkeyType to partially automate typing the codebase #1951

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

whabanks
Copy link
Contributor

@whabanks whabanks commented Jul 28, 2023

Summary | Résumé

This is an experimental PR that adds monkeytype and the Poetry plugin Poe the Poet to the project.

MonkeyType

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.

While it is very useful for automating the process of type annotating Python code bases, it is somewhat cumbersome to work with manually.

Poe the Poet

Enter Poe the Poet, a task runner similar to make that provides a simple way to define project tasks directly in pyproject.toml.

Leveraging features like composite tasks and graphs we can create a rich, fully documented ecosystem of project specific tasks.

Since all poe tasks are run from within the Poetry virtual env by default, we no longer need to ask ourselves the question "Do I need poetry run... in front of this command?", nor would we need poetry run in front of nearly every command in our makefile.

This PR leverages the plugin to create a basic suite of tasks to simplify using Monkeytype. Just run poe or poe --help to list fully documented tasks:

CONFIGURED TASKS
  trace-tests        Runs a Python test file through MonkeyType, generating a record of type annotation traces. Traces are stored in monkeytype.sqlite3
    -p, --path       Path to the test file to run. /tests/app/ can be omitted. e.g. poe trace-tests -p main/test_contact.py
    -m, --method     Name of the test method to execute and trace
  list-traces        Lists all traces awaiting application from monkeytype.sqlite3
  apply-annotations  Applies ALL type annotations generated by trace-tests.

For a deep dive into Poe the Poet check out the wiki page I put together

- Update .gitignore to exclude the monkeytype trace DB
@whabanks whabanks changed the title Add MonkeyType to test dependencies Use MonkeyType to partially automate typing the codebase Jul 28, 2023
@whabanks whabanks marked this pull request as ready for review June 21, 2024 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants