[MyPy][2/N] Fix mypy errors in small tests/ dirs (#51043)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Martin Hickey
2026-09-29 21:27:45 +01:00
committed by GitHub
co-authored by Harry Mellor Claude Opus 5.5
parent a96ee5935d
commit 5dd693122c
71 changed files with 491 additions and 301 deletions
@@ -307,7 +307,8 @@ def test_external_process_monitoring(api_server_args):
def run_with_exception_capture():
try:
wait_for_completion_or_failure(
api_server_manager=manager, coordinator=mock_coordinator
api_server_manager=manager,
coordinator=mock_coordinator, # type: ignore[arg-type]
)
except Exception as e:
result["exception"] = e
@@ -376,7 +377,7 @@ def test_gather_actual_addresses_end_to_end():
manager = APIServerProcessManager(
listen_address=f"tcp://{host}:0",
sock=sock,
args="test_args",
args="test_args", # type: ignore[arg-type]
num_servers=num_servers,
input_addresses=placeholder_inputs,
output_addresses=placeholder_outputs,
@@ -423,7 +424,7 @@ def test_gather_actual_addresses_child_crash_before_report():
manager = APIServerProcessManager(
listen_address=f"tcp://{host}:0",
sock=sock,
args="test_args",
args="test_args", # type: ignore[arg-type]
num_servers=num_servers,
input_addresses=placeholder_inputs,
output_addresses=placeholder_outputs,
@@ -108,8 +108,8 @@ async def test_unload_lora_adapter_success():
response = await serving_models.load_lora_adapter(request)
assert len(serving_models.lora_requests) == 1
request = UnloadLoRAAdapterRequest(lora_name="adapter1")
response = await serving_models.unload_lora_adapter(request)
unload_request = UnloadLoRAAdapterRequest(lora_name="adapter1")
response = await serving_models.unload_lora_adapter(unload_request)
assert response == LORA_UNLOADING_SUCCESS_MESSAGE.format(lora_name="adapter1")
assert len(serving_models.lora_requests) == 0
@@ -84,7 +84,10 @@ def task_routes(request, monkeypatch) -> tuple[str, list[tuple[str, list[str]]]]
# Register routers for this specific task (development mode already enabled).
register_api_routers(
args, app, supported_tasks=(task,), model_config=MockModelConfig()
args,
app,
supported_tasks=(task,),
model_config=MockModelConfig(), # type: ignore[arg-type]
)
routes = get_all_http_routes(app)
@@ -19,6 +19,7 @@ from vllm.entrypoints.serve.tokenize.api_router import attach_router
from vllm.entrypoints.serve.tokenize.protocol import (
TokenizeChatRequest,
TokenizeCompletionRequest,
TokenizeResponse,
)
from vllm.entrypoints.serve.tokenize.serving import ServingTokenization
from vllm.exceptions import VLLMNotFoundError, VLLMValidationError
@@ -95,7 +96,7 @@ async def test_tokenize_chat_skips_mm_cache_for_renderer_only_path():
mock_engine.renderer = MagicMock()
serving = _build_serving_tokenization(mock_engine)
serving.online_renderer.preprocess_chat = AsyncMock(
serving.online_renderer.preprocess_chat = AsyncMock( # type: ignore[method-assign]
return_value=(
[{"role": "user", "content": "Test"}],
[{"prompt_token_ids": [1, 2, 3]}],
@@ -109,7 +110,7 @@ async def test_tokenize_chat_skips_mm_cache_for_renderer_only_path():
response = await serving.create_tokenize(request, MagicMock(headers={}))
assert response.tokens == [1, 2, 3]
assert isinstance(response, TokenizeResponse) and response.tokens == [1, 2, 3]
assert (
serving.online_renderer.preprocess_chat.call_args.kwargs["skip_mm_cache"]
is True
@@ -125,7 +126,7 @@ async def test_tokenize_completion_skips_mm_cache_for_renderer_only_path():
mock_engine.renderer = MagicMock()
serving = _build_serving_tokenization(mock_engine)
serving.online_renderer.preprocess_completion = AsyncMock(
serving.online_renderer.preprocess_completion = AsyncMock( # type: ignore[method-assign]
return_value=[{"prompt_token_ids": [1, 2, 3]}]
)
@@ -136,7 +137,7 @@ async def test_tokenize_completion_skips_mm_cache_for_renderer_only_path():
response = await serving.create_tokenize(request, MagicMock(headers={}))
assert response.tokens == [1, 2, 3]
assert isinstance(response, TokenizeResponse) and response.tokens == [1, 2, 3]
assert (
serving.online_renderer.preprocess_completion.call_args.kwargs["skip_mm_cache"]
is True
@@ -101,13 +101,13 @@ async def test_tokenize_chat(
if continue_final:
conversation.append({"role": "assistant", "content": "Sure,"})
prompt = tokenizer.apply_chat_template(
prompt = tokenizer.apply_chat_template( # type: ignore[call-arg]
add_generation_prompt=add_generation,
continue_final_message=continue_final,
conversation=conversation,
tokenize=False,
)
tokens = tokenizer.encode(prompt, add_special_tokens=add_special)
tokens = tokenizer.encode(prompt, add_special_tokens=add_special) # type: ignore[arg-type]
response = requests.post(
server.url_for("tokenize"),
@@ -169,14 +169,14 @@ async def test_tokenize_chat_with_tools(
if continue_final:
conversation.append({"role": "assistant", "content": "Sure,"})
prompt = tokenizer.apply_chat_template(
prompt = tokenizer.apply_chat_template( # type: ignore[call-arg]
add_generation_prompt=add_generation,
continue_final_message=continue_final,
conversation=conversation,
tools=tools,
tokenize=False,
)
tokens = tokenizer.encode(prompt, add_special_tokens=add_special)
tokens = tokenizer.encode(prompt, add_special_tokens=add_special) # type: ignore[arg-type]
response = requests.post(
server.url_for("tokenize"),
@@ -18,7 +18,7 @@ def _cfg(tp=1, pp=1, dp=1, ep=False, digest="a3b21f94deadbeef"):
enable_expert_parallel=ep,
)
)
c.compute_hash = lambda: digest # type: ignore[attr-defined]
c.compute_hash = lambda: digest
return c
@@ -59,6 +59,7 @@ def test_get_respects_set_default():
fp.set_default_fingerprint_mode("hash")
hashed = fp.get_system_fingerprint(cfg)
assert hashed is not None
assert hashed != full
assert "tp8" not in hashed
@@ -72,5 +73,7 @@ def test_get_respects_set_default():
def test_compute_hash_failure_does_not_raise():
cfg = _cfg()
cfg.compute_hash = lambda: (_ for _ in ()).throw(RuntimeError("boom"))
assert fp.build_system_fingerprint(cfg, "full").endswith("-nohash")
assert fp.build_system_fingerprint(cfg, "hash").endswith("-nohash")
full_fp = fp.build_system_fingerprint(cfg, "full")
assert full_fp is not None and full_fp.endswith("-nohash")
hash_fp = fp.build_system_fingerprint(cfg, "hash")
assert hash_fp is not None and hash_fp.endswith("-nohash")
+18 -16
View File
@@ -17,6 +17,7 @@ from vllm.config import ModelConfig
from vllm.entrypoints.chat_utils import (
MEDIA_CONNECTOR_REGISTRY,
AsyncMultiModalItemTracker,
ChatCompletionMessageParam,
ConversationMessage,
_load_embeds_dict,
_parse_metadata_array,
@@ -215,7 +216,7 @@ def video_url():
@pytest.fixture(scope="module")
def audio_url():
audio = AudioAsset("mary_had_lamb")
return encode_audio_url(*audio.audio_and_sample_rate)
return encode_audio_url(*audio.audio_and_sample_rate) # type: ignore[arg-type]
def _assert_mm_data_is_image_input(
@@ -769,7 +770,9 @@ async def test_text_only_chat_does_not_initialize_media_connector(
):
load_connector = MagicMock()
monkeypatch.setattr(MEDIA_CONNECTOR_REGISTRY, "load", load_connector)
messages = [{"role": "user", "content": "Who are you?"}]
messages: list[ChatCompletionMessageParam] = [
{"role": "user", "content": "Who are you?"}
]
parse_chat_messages(
messages,
@@ -2457,7 +2460,7 @@ def test_parse_chat_messages_image_vision_chunk(
kimi_k2_5_model_config,
image_url,
):
messages = [
messages: list[ChatCompletionMessageParam] = [
{
"role": "user",
"content": [
@@ -2493,7 +2496,7 @@ def test_parse_chat_messages_video_vision_chunk(
kimi_k2_5_model_config,
video_url,
):
messages = [
messages: list[ChatCompletionMessageParam] = [
{
"role": "user",
"content": [
@@ -2530,7 +2533,7 @@ def test_parse_chat_messages_image_vision_chunk_with_uuid(
image_url,
):
image_uuid = "image_123"
messages = [
messages: list[ChatCompletionMessageParam] = [
{
"role": "user",
"content": [
@@ -2568,7 +2571,7 @@ def test_parse_chat_messages_video_vision_chunk_with_uuid(
video_url,
):
video_uuid = "video_456"
messages = [
messages: list[ChatCompletionMessageParam] = [
{
"role": "user",
"content": [
@@ -2606,7 +2609,7 @@ def test_parse_chat_messages_mixed_vision_chunk(
image_url,
video_url,
):
messages = [
messages: list[ChatCompletionMessageParam] = [
{
"role": "user",
"content": [
@@ -2655,7 +2658,7 @@ def test_parse_chat_messages_mixed_vision_chunk_with_uuid(
):
image_uuid = "image_123"
video_uuid = "video_456"
messages = [
messages: list[ChatCompletionMessageParam] = [
{
"role": "user",
"content": [
@@ -2707,7 +2710,7 @@ async def test_parse_chat_messages_mixed_vision_chunk_async(
image_url,
video_url,
):
messages = [
messages: list[ChatCompletionMessageParam] = [
{
"role": "user",
"content": [
@@ -2757,7 +2760,7 @@ async def test_parse_chat_messages_mixed_vision_chunk_with_uuid_async(
):
image_uuid = "image_123"
video_uuid = "video_456"
messages = [
messages: list[ChatCompletionMessageParam] = [
{
"role": "user",
"content": [
@@ -2808,7 +2811,7 @@ async def test_parse_chat_messages_image_vision_chunk_async(
kimi_k2_5_model_config,
image_url,
):
messages = [
messages: list[ChatCompletionMessageParam] = [
{
"role": "user",
"content": [
@@ -2845,7 +2848,7 @@ async def test_parse_chat_messages_video_vision_chunk_async(
kimi_k2_5_model_config,
video_url,
):
messages = [
messages: list[ChatCompletionMessageParam] = [
{
"role": "user",
"content": [
@@ -2883,7 +2886,7 @@ async def test_parse_chat_messages_image_vision_chunk_with_uuid_async(
image_url,
):
image_uuid = "image_123"
messages = [
messages: list[ChatCompletionMessageParam] = [
{
"role": "user",
"content": [
@@ -2922,7 +2925,7 @@ async def test_parse_chat_messages_video_vision_chunk_with_uuid_async(
video_url,
):
video_uuid = "video_456"
messages = [
messages: list[ChatCompletionMessageParam] = [
{
"role": "user",
"content": [
@@ -2997,8 +3000,7 @@ async def test_resolve_items_runs_modalities_concurrently_and_preserves_order():
finally:
active_fetches -= 1
tracker = AsyncMultiModalItemTracker(MagicMock())
tracker._model_config.is_multimodal_model = True
tracker = AsyncMultiModalItemTracker(MagicMock(is_multimodal_model=True))
tracker.__dict__["mm_processor"] = MagicMock()
tracker._items_by_modality["video"] = [
lambda: _fetch("video-0", 0.02),