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

Enable strict type checking with mypy #6397

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

neubig
Copy link
Contributor

@neubig neubig commented Jan 21, 2025

This PR enables stricter type checking with mypy by:

  1. Updating mypy configuration with stricter type checking rules:

    • Enable more error checks
    • Show error codes and column numbers
    • Disallow untyped definitions and decorators
    • Enable more warnings
  2. Adding more type stubs to pre-commit configuration:

    • Add types for redis, protobuf, dateutil, jwt, etc.
    • Add types for common dependencies like Jinja2, click, etc.
  3. Improving CI configuration:

    • Run mypy both through pre-commit and directly
    • Install project in editable mode for better type checking
    • Set correct PYTHONPATH in CI environment

This will help catch type errors earlier and improve code quality. The PR is marked as draft because it will likely fail CI due to the stricter type checking - we will need to fix the type errors in follow-up PRs.

Fixes #6396

I'll send separate PRs to fix the linter errors directory by directory to keep things manageable.


To run this PR locally, use the following command:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:64ebef3-nikolaik   --name openhands-app-64ebef3   docker.all-hands.dev/all-hands-ai/openhands:64ebef3

- Update mypy configuration with stricter type checking rules
- Add more type stubs to pre-commit configuration
- Run mypy both through pre-commit and directly in CI
- Install project in editable mode for better type checking
- Set correct PYTHONPATH in CI environment
@raymyers
Copy link
Contributor

Generally happy to see this change and if I can be of help chipping away at some of the fixes let me know.

I haven't tried them but there are various reports mypy can run on the thoroughness of type coverage, might be worth a look if not already using.

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.

[Bug]: pre-commit mypy does not catch errors
3 participants