chore(python): enforce strict type-checking across a2ui_core#1615
chore(python): enforce strict type-checking across a2ui_core#1615jiahaog wants to merge 4 commits into
Conversation
- Configured strict MyPy checking (strict=True) and pydantic plugin in pyproject.toml. - Added precise type annotations and typing.cast() across src/ and tests/ directories. - Refactored __init__.py files for explicit re-exports. - Added MyPy type check step to Github Actions CI.
There was a problem hiding this comment.
Code Review
This pull request configures strict type-checking with MyPy for the a2ui_core Python SDK, adding type annotations across the codebase and introducing a py.typed marker. The review feedback focuses on refining these annotations to ensure correctness and type safety. Specifically, several parameters typed as Optional[Dict[str, Any]] (such as context) should be relaxed to Optional[Any] to support custom context objects with dynamic resolution methods. Conversely, other types, such as the execute callback in create_function_implementation and the self.functions dictionary, should be tightened to prevent type safety issues. Finally, a signature mismatch in CoercedFunctionImplementation.execute needs to be resolved to avoid violating the Liskov Substitution Principle.
- Relaxed `context` types from `Optional[Dict[str, Any]]` to `Optional[Any]` across functions and catalog APIs. - Removed default arguments from lambda functional implementations for precise Callable matching. - Tightened `self.functions` dict in ModelCatalog to map exactly to `Union[FunctionImplementation, FunctionApi]`. - Aligned `execute` implementation signatures to satisfy Liskov Substitution Principle.
|
AI comment: I have implemented all the suggested changes and pushed a new commit:
All MyPy type-checks continue to pass with |
|
Thanks for the update, @jiahaog! The changes look solid and correctly address the type-checking requirements while maintaining the Liskov Substitution Principle. The adjustments to |
- Updated `test_generate_client_capabilities` to correctly assert the literal version string `v0.9` instead of `SPEC_VERSION` to match the updated generator logic.
- Fixes the failing GitHub Actions CI typechecking step which complained about missing stubs for the `jsonschema` library.
Towards #1614.