Skip to content

Commit

Permalink
Enable strict type checking with mypy
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
openhands-agent committed Jan 21, 2025
1 parent 5b7fcfb commit 66bd8fd
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,20 @@ jobs:
cache: 'pip'
- name: Install pre-commit
run: pip install pre-commit==3.7.0
- name: Install project in editable mode
run: pip install -e .
- name: Run pre-commit hooks
run: pre-commit run --files openhands/**/* evaluation/**/* tests/**/* --show-diff-on-failure --config ./dev_config/python/.pre-commit-config.yaml
- name: Run mypy directly (for better error reporting)
if: always() # Run even if pre-commit fails
run: |
pip install mypy==1.9.0 \
types-requests types-setuptools types-pyyaml types-toml \
types-redis types-protobuf types-python-dateutil types-pyjwt \
types-docutils types-Pillow types-boto3 types-cryptography \
types-Jinja2 types-MarkupSafe types-click types-filelock \
types-decorator types-docopt types-emoji types-enum34 types-paramiko
PYTHONPATH=$PWD mypy --config-file dev_config/python/mypy.ini --scripts-are-modules openhands/
# Check version consistency across documentation
check-version-consistency:
Expand Down
26 changes: 24 additions & 2 deletions dev_config/python/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,30 @@ repos:
rev: v1.9.0
hooks:
- id: mypy
name: mypy (with strict type checking)
additional_dependencies:
[types-requests, types-setuptools, types-pyyaml, types-toml]
entry: mypy --config-file dev_config/python/mypy.ini openhands/
- types-requests
- types-setuptools
- types-pyyaml
- types-toml
- types-redis
- types-protobuf
- types-python-dateutil
- types-pyjwt
- types-docutils
- types-Pillow
- types-boto3
- types-cryptography
- types-Jinja2
- types-MarkupSafe
- types-click
- types-filelock
- types-decorator
- types-docopt
- types-emoji
- types-enum34
- types-paramiko
entry: mypy --config-file dev_config/python/mypy.ini --scripts-are-modules openhands/
always_run: true
pass_filenames: false
verbose: true
28 changes: 24 additions & 4 deletions dev_config/python/mypy.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
[mypy]
warn_unused_configs = True
# Error output
show_error_codes = True
pretty = True
show_column_numbers = True

# Import discovery
ignore_missing_imports = True
follow_imports = normal

# Untyped definitions and calls
disallow_untyped_defs = True
check_untyped_defs = True
explicit_package_bases = True
warn_unreachable = True
warn_redundant_casts = True
disallow_incomplete_defs = True
disallow_untyped_decorators = True

# None and Optional handling
no_implicit_optional = True
strict_optional = True

# Warnings
warn_unused_configs = True
warn_redundant_casts = True
warn_unused_ignores = True
warn_return_any = True
warn_unreachable = True

# Misc
explicit_package_bases = True

0 comments on commit 66bd8fd

Please sign in to comment.