chore: fix mypy warnings in tests/api
What does this merge request do and why?
This MR fixes all mypy warnings on tests/api folder.
# Remove `ai_gateway/experimentation` from https://gitlab.com/gitlab-org/modelops/applied-ml/code-suggestions/ai-assist/-/blob/main/Makefile#L20
❯ make check-mypy
--snip--
Running mypy check...
tests/api/v3/test_v3_code.py:324: error: Invalid index type "str" for "str"; expected type "SupportsIndex | slice[Any, Any, Any]" [index]
tests/api/v3/test_v3_code.py:700: error: Argument "endpoint" to "ModelMetadata" has incompatible type "str"; expected "Url" [arg-type]
tests/api/v3/test_v3_code.py:948: error: Invalid index type "str" for "str"; expected type "SupportsIndex | slice[Any, Any, Any]" [index]
tests/api/v2/test_v2_code.py:446: error: List comprehension has incompatible type List[Message]; expected List[dict[str, str]] [misc]
tests/api/v2/test_v2_code.py:446: error: Argument "role" to "Message" has incompatible type "str"; expected "Role" [arg-type]
tests/api/v2/test_v2_code.py:449: error: Dict entry 0 has incompatible type "str": "list[dict[str, str]]"; expected "str": "list[str]" [dict-item]
tests/api/v2/test_v2_code.py:1329: error: Argument 1 to "set" of "ContextVar" has incompatible type "list[Never]"; expected "set[str]" [arg-type]
tests/api/v2/test_v2_code.py:1373: error: Argument 1 to "set" of "ContextVar" has incompatible type "list[Never]"; expected "set[str]" [arg-type]
tests/api/v2/test_v2_chat_agent.py:75: error: Incompatible return value type (got "AgentBaseEvent", expected "str") [return-value]
tests/api/v2/test_v2_chat_agent.py:84: error: Missing named argument "model_metadata" for "AgentRequest" [call-arg]
tests/api/v2/test_v2_chat_agent.py:106: error: Argument "endpoint" to "ModelMetadata" has incompatible type "str"; expected "Url" [arg-type]
tests/api/v2/test_v2_chat_agent.py:164: error: Argument "endpoint" to "ModelMetadata" has incompatible type "str"; expected "Url" [arg-type]
tests/api/v2/test_v2_chat_agent.py:173: error: Missing named argument "model_metadata" for "AgentRequest" [call-arg]
tests/api/v2/test_v2_chat_agent.py:213: error: Argument 2 to "chunk_to_model" has incompatible type "type[AgentFinalAnswer]"; expected "AgentBaseEvent" [arg-type]
tests/api/v2/test_v2_chat_agent.py:272: error: Argument "endpoint" to "ModelMetadata" has incompatible type "str"; expected "Url" [arg-type]
tests/api/v2/test_v2_chat_agent.py:325: error: Argument 2 to "chunk_to_model" has incompatible type "type[AgentToolAction]"; expected "AgentBaseEvent" [arg-type]
tests/api/v2/test_v2_chat_agent.py:341: error: Unexpected keyword argument "model_metadata" for "ReActAgentInputs" [call-arg]
tests/api/v2/test_v2_chat_agent.py:366: error: Missing named argument "model_metadata" for "AgentRequest" [call-arg]
tests/api/v2/test_v2_chat_agent.py:375: error: Missing named argument "model_metadata" for "AgentRequest" [call-arg]
tests/api/v2/test_v2_chat_agent.py:385: error: Missing named argument "model_metadata" for "AgentRequest" [call-arg]
tests/api/v2/test_v2_chat_agent.py:408: error: Missing named argument "model_metadata" for "AgentRequest" [call-arg]
tests/api/v2/test_v2_chat_agent.py:436: error: Missing named argument "model_metadata" for "AgentRequest" [call-arg]
tests/api/v2/test_v2_chat_agent.py:453: error: Missing named argument "model_metadata" for "AgentRequest" [call-arg]
tests/api/v2/test_v2_chat_agent.py:471: error: Missing named argument "model_metadata" for "AgentRequest" [call-arg]
tests/api/v2/test_v2_chat_agent.py:516: error: Missing named argument "model_metadata" for "AgentRequest" [call-arg]
tests/api/v2/test_v2_chat_agent.py:630: error: Argument 2 to "chunk_to_model" has incompatible type "type[AgentFinalAnswer]"; expected "AgentBaseEvent" [arg-type]
tests/api/v1/test_v1_search_docs.py:136: error: Function "tests.api.v1.test_v1_search_docs.request_body" is not valid as a type [valid-type]
tests/api/v1/test_v1_search_docs.py:136: note: Perhaps you need "Callable[...]" or a callback protocol?
tests/api/v1/test_v1_prompts.py:71: error: Argument 1 to "len" has incompatible type "list[str] | None"; expected "Sized" [arg-type]
tests/api/v1/test_v1_prompts.py:249: error: Argument 1 to "len" has incompatible type "list[str] | None"; expected "Sized" [arg-type]
Found 29 errors in 5 files (checked 158 source files)
make: *** [Makefile:99: check-mypy] Error 1
How to set up and validate locally
- Check out to this merge request's branch.
- Ensure the following commands do not result in any warnings (they are already run as part of CI).
make check-mypy make test
Merge request checklist
-
Tests added for new functionality. If not, please raise an issue to follow up. -
Documentation added/updated, if needed.
Contributes to #715 (closed)
Edited by Tan Le