From 66bd8fdbcdbc3329694614870d1930718cf5baa7 Mon Sep 17 00:00:00 2001 From: openhands Date: Tue, 21 Jan 2025 19:12:09 +0000 Subject: [PATCH 1/3] Enable strict type checking with mypy - 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 --- .github/workflows/lint.yml | 12 ++++++++++ dev_config/python/.pre-commit-config.yaml | 26 +++++++++++++++++++-- dev_config/python/mypy.ini | 28 +++++++++++++++++++---- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 789a938e1d7e..170ea3560e27 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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: diff --git a/dev_config/python/.pre-commit-config.yaml b/dev_config/python/.pre-commit-config.yaml index 0ae868fe70fd..25569a132af1 100644 --- a/dev_config/python/.pre-commit-config.yaml +++ b/dev_config/python/.pre-commit-config.yaml @@ -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 diff --git a/dev_config/python/mypy.ini b/dev_config/python/mypy.ini index 84b97d720b2f..72081060a20d 100644 --- a/dev_config/python/mypy.ini +++ b/dev_config/python/mypy.ini @@ -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 From 7a259915c1748b1b9e999f5f02450658e95e4c7e Mon Sep 17 00:00:00 2001 From: Graham Neubig Date: Tue, 21 Jan 2025 14:47:51 -0500 Subject: [PATCH 2/3] Update .github/workflows/lint.yml --- .github/workflows/lint.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 170ea3560e27..db7ae1f9c90f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -55,16 +55,6 @@ jobs: 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: From 64ebef3646487a92ca2acd639a262620f9c67ac5 Mon Sep 17 00:00:00 2001 From: Graham Neubig Date: Tue, 21 Jan 2025 14:52:56 -0500 Subject: [PATCH 3/3] Update .github/workflows/lint.yml --- .github/workflows/lint.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index db7ae1f9c90f..170ea3560e27 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -55,6 +55,16 @@ jobs: 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: