From 2eeb6b46f036e8433ee29835b27107e7551f69a7 Mon Sep 17 00:00:00 2001 From: Sara Robinson Date: Mon, 26 Jan 2026 20:06:39 -0500 Subject: [PATCH 01/11] chore: Add GitHub Action check to run mypy --- .github/workflows/mypy.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/mypy.yml diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml new file mode 100644 index 0000000000..d1be76d2f2 --- /dev/null +++ b/.github/workflows/mypy.yml @@ -0,0 +1,30 @@ +name: Mypy Static Type Check + +on: + pull_request: + branches: [ main ] + +jobs: + mypy: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.10', '3.11', '3.12', '3.13', '3.14'] + + steps: + - uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v1 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: uv sync --all-extras + + - name: Run mypy + + run: uv run mypy . --strict From dac7c962b155bfb65d958234755aec2dfdb88dda Mon Sep 17 00:00:00 2001 From: Sara Robinson Date: Mon, 26 Jan 2026 20:34:05 -0500 Subject: [PATCH 02/11] Update trigger conditions --- .github/workflows/mypy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index d1be76d2f2..c386d1eb46 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -1,6 +1,8 @@ name: Mypy Static Type Check on: + push: + branches: [ main ] pull_request: branches: [ main ] From 4793188545781199446c8c2417b196e53cc0e702 Mon Sep 17 00:00:00 2001 From: Sara Robinson Date: Mon, 26 Jan 2026 20:40:52 -0500 Subject: [PATCH 03/11] Fix indentation --- .github/workflows/mypy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index c386d1eb46..e79dfd5c6e 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -10,8 +10,8 @@ jobs: mypy: runs-on: ubuntu-latest strategy: - matrix: - python-version: ['3.10', '3.11', '3.12', '3.13', '3.14'] + matrix: + python-version: ['3.10', '3.11', '3.12', '3.13', '3.14'] steps: - uses: actions/checkout@v4 From 73e60730329891e0cd13de4e9ea2ce41ad2933a1 Mon Sep 17 00:00:00 2001 From: Sara Robinson Date: Tue, 27 Jan 2026 09:48:51 -0500 Subject: [PATCH 04/11] Exclude samples from mypy check --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f60494f255..78427c848b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -216,7 +216,7 @@ asyncio_mode = "auto" [tool.mypy] python_version = "3.10" -exclude = "tests/" +exclude = ["tests/", "contributing/samples/"] plugins = ["pydantic.mypy"] # Start with non-strict mode, and swtich to strict mode later. # strict = true From 3543211c3bce924f21114844455dbe3d9e22f8e0 Mon Sep 17 00:00:00 2001 From: Sara Robinson Date: Tue, 27 Jan 2026 10:18:10 -0500 Subject: [PATCH 05/11] Add check to prevent new errors --- .github/workflows/mypy-new-errors.yml | 72 +++++++++++++++++++++++++++ .github/workflows/mypy.yml | 4 +- 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/mypy-new-errors.yml diff --git a/.github/workflows/mypy-new-errors.yml b/.github/workflows/mypy-new-errors.yml new file mode 100644 index 0000000000..6484610c89 --- /dev/null +++ b/.github/workflows/mypy-new-errors.yml @@ -0,0 +1,72 @@ +name: Mypy New Error Check + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + + +jobs: + mypy-diff: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.10', '3.11', '3.12', '3.13',] + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install uv + uses: astral-sh/setup-uv@v5 + + - name: Generate Baseline (Main) + run: | + # Switch to main branch to generate baseline + git checkout origin/main + + # Install dependencies for main + uv venv .venv + source .venv/bin/activate + uv sync --all-extras + + # Run mypy, filter for errors only, remove line numbers (file:123: -> file::), and sort + # We ignore exit code (|| true) because we expect errors on main + uv run mypy . | grep "error:" | sed 's/:\([0-9]\+\):/::/g' | sort > main_errors.txt || true + + echo "Found $(wc -l < main_errors.txt) errors on main." + + - name: Check PR Branch + run: | + # Switch back to the PR commit + git checkout ${{ github.sha }} + + # Re-sync dependencies in case the PR changed them + source .venv/bin/activate + uv sync --all-extras + + # Run mypy on PR code, apply same processing + uv run mypy . | grep "error:" | sed 's/:\([0-9]\+\):/::/g' | sort > pr_errors.txt || true + + echo "Found $(wc -l < pr_errors.txt) errors on PR branch." + + - name: Compare and Fail on New Errors + run: | + # 'comm -13' suppresses unique lines in file1 (main) and common lines, + # leaving only lines unique to file2 (PR) -> The new errors. + comm -13 main_errors.txt pr_errors.txt > new_errors.txt + + if [ -s new_errors.txt ]; then + echo "::error::The following NEW mypy errors were introduced:" + cat new_errors.txt + exit 1 + else + echo "Great job! No new mypy errors introduced." + fi diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index e79dfd5c6e..085ab68e93 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -1,4 +1,4 @@ -name: Mypy Static Type Check +name: Mypy Type Check on: push: @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.10', '3.11', '3.12', '3.13', '3.14'] + python-version: ['3.10', '3.11', '3.12', '3.13',] steps: - uses: actions/checkout@v4 From 458876af35ea8f1c769013eaf9fc9eb6c360835a Mon Sep 17 00:00:00 2001 From: Sara Robinson Date: Tue, 27 Jan 2026 10:24:01 -0500 Subject: [PATCH 06/11] Update baseline check --- .github/workflows/mypy-new-errors.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/mypy-new-errors.yml b/.github/workflows/mypy-new-errors.yml index 6484610c89..85dd0073c1 100644 --- a/.github/workflows/mypy-new-errors.yml +++ b/.github/workflows/mypy-new-errors.yml @@ -31,6 +31,8 @@ jobs: run: | # Switch to main branch to generate baseline git checkout origin/main + + git checkout ${{ github.sha }} -- pyproject.toml # Install dependencies for main uv venv .venv From 06e0eb37f684c706e34324fa51d6919cfab163cf Mon Sep 17 00:00:00 2001 From: Sara Robinson Date: Tue, 27 Jan 2026 10:25:54 -0500 Subject: [PATCH 07/11] Test new error check fails --- src/google/adk/a2a/converters/event_converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/adk/a2a/converters/event_converter.py b/src/google/adk/a2a/converters/event_converter.py index 59bbefa1f0..d604f8b256 100644 --- a/src/google/adk/a2a/converters/event_converter.py +++ b/src/google/adk/a2a/converters/event_converter.py @@ -105,7 +105,7 @@ def _serialize_metadata_value(value: Any) -> str: def _get_context_metadata( - event: Event, invocation_context: InvocationContext + event, invocation_context: InvocationContext ) -> Dict[str, str]: """Gets the context metadata for the event. From 8354c1219236ab6cb678a6a3e69ddeee11cae20a Mon Sep 17 00:00:00 2001 From: Sara Robinson Date: Tue, 27 Jan 2026 10:39:03 -0500 Subject: [PATCH 08/11] Enable strict mode in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 78427c848b..08acb1db4b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -219,6 +219,6 @@ python_version = "3.10" exclude = ["tests/", "contributing/samples/"] plugins = ["pydantic.mypy"] # Start with non-strict mode, and swtich to strict mode later. -# strict = true +strict = true disable_error_code = ["import-not-found", "import-untyped", "unused-ignore"] follow_imports = "skip" From 56ce9bb27f032663f0ba5f923b3bf7f8b8340c8a Mon Sep 17 00:00:00 2001 From: Sara Robinson Date: Tue, 27 Jan 2026 10:43:19 -0500 Subject: [PATCH 09/11] Remove test mypy change --- src/google/adk/a2a/converters/event_converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/adk/a2a/converters/event_converter.py b/src/google/adk/a2a/converters/event_converter.py index d604f8b256..59bbefa1f0 100644 --- a/src/google/adk/a2a/converters/event_converter.py +++ b/src/google/adk/a2a/converters/event_converter.py @@ -105,7 +105,7 @@ def _serialize_metadata_value(value: Any) -> str: def _get_context_metadata( - event, invocation_context: InvocationContext + event: Event, invocation_context: InvocationContext ) -> Dict[str, str]: """Gets the context metadata for the event. From e0bf8e1ea911a5ab41ddd7af93d19eb2cf37d491 Mon Sep 17 00:00:00 2001 From: Sara Robinson Date: Tue, 27 Jan 2026 11:07:57 -0500 Subject: [PATCH 10/11] Test line number change doesn't cause mypy diff test to fail --- src/google/adk/cli/conformance/cli_record.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/google/adk/cli/conformance/cli_record.py b/src/google/adk/cli/conformance/cli_record.py index 7d3849493d..9cbd9192c3 100644 --- a/src/google/adk/cli/conformance/cli_record.py +++ b/src/google/adk/cli/conformance/cli_record.py @@ -51,6 +51,7 @@ async def _create_conformance_test_files( state=test_case.test_spec.initial_state, ) + # Run the agent with the user messages function_call_name_to_id_map = {} for user_message_index, user_message in enumerate( From 76af7118713e98b1b1fed0729ec9eb54717412f7 Mon Sep 17 00:00:00 2001 From: Sara Robinson Date: Tue, 27 Jan 2026 11:11:09 -0500 Subject: [PATCH 11/11] Revert test change --- src/google/adk/cli/conformance/cli_record.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/google/adk/cli/conformance/cli_record.py b/src/google/adk/cli/conformance/cli_record.py index 9cbd9192c3..7d3849493d 100644 --- a/src/google/adk/cli/conformance/cli_record.py +++ b/src/google/adk/cli/conformance/cli_record.py @@ -51,7 +51,6 @@ async def _create_conformance_test_files( state=test_case.test_spec.initial_state, ) - # Run the agent with the user messages function_call_name_to_id_map = {} for user_message_index, user_message in enumerate(