Add type hints and check them with mypy

Python promptsDifficulty: Intermediate Last updated: 16 November 2026

Usage description

Improve the quality of existing Python code by adding types without changing its behaviour.

Prompt text

Prompt
The code is in {{project}} ({{stack}}).
Add type hints gradually:
1. Start with the core modules that depend least on others.
2. Use precise types (TypedDict, Protocol, Literal) instead of Any where possible.
3. Run mypy --strict on each module after changing it, and fix the errors without changing the behaviour.
4. Run the existing tests after each module.
5. Write a summary of the completed and remaining modules and any unresolved errors with their cause.
{{extra}}

Required inputs

The project path and the Python version.

Expected outputs

Typed changes, a mypy report and the test results.

Suitable tools

Practical example

project = "an internal data processing library" of about 40 files without types.

Rate:
No ratings yet

We do not claim this prompt was tested on a particular model; results vary with the model and context, so always review the output.

Create a custom version with AI

Do not write secrets, keys or personal data. The description is merged with the prompt directly, without sending it to any external service.