Repository navigation
fix(python): enable strict mypy on experimental inference formats - #4248
gspencergoog merged 2 commits into
Conversation
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
There was a problem hiding this comment.
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.
ditman
left a comment
There was a problem hiding this comment.
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.
|
Removed both tests and their helpers, so 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 |
Yep, this is good regardless of what happens to those formats. |
Summary
Remove stale
[tool.mypy].excludeentries inpyproject.tomland fix all strictmypyannotations acrossa2ui.inference_formats.experimental(atomandelemental).Fixes #4247
Changes
#1614comment,"^python/a2ui_agent/src/a2ui/inference_formats/experimental/", and dead"^hooks\\.py$"from[tool.mypy].excludeinpyproject.toml.Form(list[Any])inatom/sexpr.py, narrow return andForm/dicttypes inatom/compiler.py, and narrow schema enum and catalog ID lookups inatom/prompt_generator.py.HTMLParseroverrides and_CompileContext.__init__inelemental/compiler.py, parameterizelist/dictannotations inelemental/decompiler.py, and narrowcatalog_idlookup inelemental/prompt_generator.py.Impact & Risks
AtomFormatandElementalFormatare unchanged.uv run --all-packages mypy .now checks 238 source files (up from 223) understrict = true.Testing
uv run --all-packages mypy .and verify zero issues across all 238 source files.uv run pytest python/a2ui_agent -qand verify all unit and conformance tests pass.