Skip to content

fix(python): enable strict mypy on experimental inference formats - #4248

Merged
gspencergoog merged 2 commits into
a2ui-project:mainfrom
gspencergoog:fix-something/20261115-mypy-1614
Nov 17, 2026
Merged

gspencergoog merged 2 commits into
a2ui-project:mainfrom
gspencergoog:fix-something/20261115-mypy-1614

Conversation

@gspencergoog

@gspencergoog gspencergoog commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Architecture & Contract Brief

  • Root cause: pyproject.toml excluded experimental/ and dead hooks.py from mypy, hiding 19 strict errors across 6 atom and elemental files.
  • Contract impact: Public a2ui_agent APIs and runtime compilation/decompilation outputs are unchanged.
  • Key judgment call: Resolved all 19 strict errors via explicit type parameters and isinstance narrowing with zero # type: ignore suppressions.

Summary

Remove stale [tool.mypy].exclude entries in pyproject.toml and fix all strict mypy annotations across a2ui.inference_formats.experimental (atom and elemental).

Fixes #4247

Changes

  • Remove the closed #1614 comment, "^python/a2ui_agent/src/a2ui/inference_formats/experimental/", and dead "^hooks\\.py$" from [tool.mypy].exclude in pyproject.toml.
  • Parameterize Form(list[Any]) in atom/sexpr.py, narrow return and Form/dict types in atom/compiler.py, and narrow schema enum and catalog ID lookups in atom/prompt_generator.py.
  • Annotate HTMLParser overrides and _CompileContext.__init__ in elemental/compiler.py, parameterize list/dict annotations in elemental/decompiler.py, and narrow catalog_id lookup in elemental/prompt_generator.py.

Impact & Risks

  • Public exports and wire outputs of AtomFormat and ElementalFormat are unchanged.
  • uv run --all-packages mypy . now checks 238 source files (up from 223) under strict = true.

Testing

  1. Run uv run --all-packages mypy . and verify zero issues across all 238 source files.
  2. Run uv run pytest python/a2ui_agent -q and verify all unit and conformance tests pass.

Remove stale [tool.mypy].exclude entries in pyproject.toml (a2ui-project#1614 and hooks.py), add strict type annotations across experimental atom and elemental modules without suppressions, and guard against future exclusions in test_formats.py.

Fixes a2ui-project#4247

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enables mypy type-checking for the experimental inference formats by removing them from the exclude list in pyproject.toml and adding the necessary type annotations, type guards, and generic type parameters across the experimental codebase. It also adds tests to validate the mypy configuration. The feedback suggests gracefully handling a potential ImportError when importing tomli on Python versions older than 3.11 in the test suite to prevent test failures.

Comment thread python/a2ui_agent/tests/test_formats.py Resolved
@gspencergoog
gspencergoog marked this pull request as ready for review November 16, 2026 16:09
@gspencergoog
gspencergoog requested a review from ditman November 16, 2026 16:26

@ditman ditman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM!

Should we drop test_mypy_config_includes_experimental_inference_formats and test_mypy_exclude_validator_handles_regex_and_directory_forms (along with the _PLAIN_ANCHORED_PATH_RE, _load_toml_file, _experimental_mypy_targets, and _assert_mypy_excludes_valid helpers above)?

Parsing the root pyproject.toml and validating [tool.mypy].exclude regexes feels a bit out of place in test_formats.py compared to the rest of the format behavior tests here, especially since we don't have tests checking that other formats like express or direct_json are covered by mypy. Since [tool.mypy].exclude is opt-out and python-ci runs uv run --all-packages mypy . across the repo, removing experimental/ from the exclude list is already enforced in CI.

Also, are we keeping atom and elemental around? I thought we may be removing them?

Review feedback: the tests parsed the root pyproject.toml to assert that
[tool.mypy].exclude does not cover experimental/. The Type Check step in
python_ci.yml already runs mypy over every path that is not excluded, so
the tests duplicated CI and did not belong with the format behavior
tests. Restore test_formats.py to its content on main.
@gspencergoog

Copy link
Copy Markdown
Collaborator Author

Removed both tests and their helpers, so test_formats.py matches main again. The Type Check step in python_ci.yml runs uv run --all-packages mypy ., which covers everything not listed in [tool.mypy].exclude, so experimental/ is checked without a dedicated test.

We haven't decided whether or not to remove atom and elemental, but I'm leaning towards removing them eventually. We should still have mypy checks on future experimental inference formats, though.

🤖 Agent-generated

@ditman

ditman commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

We should still have mypy checks on future experimental inference formats, though.

Yep, this is good regardless of what happens to those formats.

@gspencergoog
gspencergoog merged commit 6dc5337 into a2ui-project:main Nov 17, 2026
49 checks passed
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.

python(a2ui_agent): enable strict mypy on experimental inference formats

2 participants