Disable mypy arg-type and assignment checks in tests (#59428)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
17e9295dd5
commit
fc2c801ad9
@@ -81,7 +81,7 @@ class TestRoleToMelody:
|
||||
# reject non-strings — any exception type is acceptable as long
|
||||
# as we don't silently produce a malformed prompt.
|
||||
with pytest.raises((AttributeError, TypeError, ValueError)):
|
||||
_role_to_melody(None) # type: ignore[arg-type]
|
||||
_role_to_melody(None)
|
||||
|
||||
|
||||
# ======================================================================
|
||||
@@ -135,7 +135,7 @@ class TestNormalizeToolCall:
|
||||
|
||||
def test_invalid_type_rejected(self):
|
||||
with pytest.raises(TypeError, match="Unexpected tool_call value"):
|
||||
_normalize_tool_call(42) # type: ignore[arg-type]
|
||||
_normalize_tool_call(42)
|
||||
|
||||
|
||||
# ======================================================================
|
||||
@@ -249,7 +249,7 @@ class TestDocumentToMelody:
|
||||
|
||||
def test_invalid_type_rejected(self):
|
||||
with pytest.raises(TypeError, match="Unsupported document type"):
|
||||
_document_to_melody(42) # type: ignore[arg-type]
|
||||
_document_to_melody(42)
|
||||
|
||||
|
||||
# ======================================================================
|
||||
@@ -302,7 +302,7 @@ class TestToolToMelody:
|
||||
|
||||
def test_invalid_type_rejected(self):
|
||||
with pytest.raises(TypeError, match="Unsupported tool type"):
|
||||
_tool_to_melody(42) # type: ignore[arg-type]
|
||||
_tool_to_melody(42)
|
||||
|
||||
|
||||
# ======================================================================
|
||||
@@ -418,7 +418,7 @@ class TestConversationToMelody:
|
||||
{"role": "user", "content": "hi"},
|
||||
{"role": "assistant", "content": "hello"},
|
||||
]
|
||||
out = _conversation_to_melody_messages(conv) # type: ignore[arg-type]
|
||||
out = _conversation_to_melody_messages(conv)
|
||||
assert out == [
|
||||
{
|
||||
"role": "user",
|
||||
@@ -443,7 +443,7 @@ class TestConversationToMelody:
|
||||
"reasoning": "thoughts",
|
||||
}
|
||||
]
|
||||
out = _conversation_to_melody_messages(conv) # type: ignore[arg-type]
|
||||
out = _conversation_to_melody_messages(conv)
|
||||
assert out[0]["content"] == [
|
||||
{"type": MelodyContentType.THINKING, "thinking": "thoughts"},
|
||||
{"type": MelodyContentType.TEXT, "text": "answer"},
|
||||
@@ -457,7 +457,7 @@ class TestConversationToMelody:
|
||||
"reasoning_content": "thoughts",
|
||||
}
|
||||
]
|
||||
out = _conversation_to_melody_messages(conv) # type: ignore[arg-type]
|
||||
out = _conversation_to_melody_messages(conv)
|
||||
assert out[0]["content"][0] == {
|
||||
"type": MelodyContentType.THINKING,
|
||||
"thinking": "thoughts",
|
||||
@@ -474,7 +474,7 @@ class TestConversationToMelody:
|
||||
"reasoning": "should be ignored",
|
||||
}
|
||||
]
|
||||
out = _conversation_to_melody_messages(conv) # type: ignore[arg-type]
|
||||
out = _conversation_to_melody_messages(conv)
|
||||
assert out[0]["content"] == [{"type": MelodyContentType.TEXT, "text": "hi"}]
|
||||
|
||||
def test_tool_calls_normalized(self):
|
||||
@@ -491,7 +491,7 @@ class TestConversationToMelody:
|
||||
],
|
||||
}
|
||||
]
|
||||
out = _conversation_to_melody_messages(conv) # type: ignore[arg-type]
|
||||
out = _conversation_to_melody_messages(conv)
|
||||
assert out[0]["tool_calls"] == [
|
||||
{"id": "c1", "name": "f", "parameters": '{"a":1}'}
|
||||
]
|
||||
@@ -504,7 +504,7 @@ class TestConversationToMelody:
|
||||
"tool_call_id": "c1",
|
||||
}
|
||||
]
|
||||
out = _conversation_to_melody_messages(conv) # type: ignore[arg-type]
|
||||
out = _conversation_to_melody_messages(conv)
|
||||
assert out[0]["tool_call_id"] == "c1"
|
||||
|
||||
def test_messages_citations_attached_by_index(self):
|
||||
@@ -531,20 +531,20 @@ class TestConversationToMelody:
|
||||
}
|
||||
]
|
||||
}
|
||||
out = _conversation_to_melody_messages(conv, citations) # type: ignore[arg-type]
|
||||
out = _conversation_to_melody_messages(conv, citations)
|
||||
assert "citations" not in out[0]
|
||||
assert out[1]["citations"] == citations[1]
|
||||
|
||||
def test_messages_citations_none_is_a_no_op(self):
|
||||
conv = [{"role": "assistant", "content": "a"}]
|
||||
out = _conversation_to_melody_messages(conv, None) # type: ignore[arg-type]
|
||||
out = _conversation_to_melody_messages(conv, None)
|
||||
assert "citations" not in out[0]
|
||||
|
||||
def test_messages_citations_missing_index_is_a_no_op(self):
|
||||
# A ``messages_citations`` dict whose key doesn't hit any
|
||||
# message must not attach anything (and must not raise).
|
||||
conv = [{"role": "assistant", "content": "a"}]
|
||||
out = _conversation_to_melody_messages(conv, {5: [{"anything": 1}]}) # type: ignore[arg-type]
|
||||
out = _conversation_to_melody_messages(conv, {5: [{"anything": 1}]})
|
||||
assert "citations" not in out[0]
|
||||
|
||||
def test_tool_message_v2_content_replaces_default_content(self):
|
||||
@@ -575,7 +575,7 @@ class TestConversationToMelody:
|
||||
]
|
||||
}
|
||||
out = _conversation_to_melody_messages(
|
||||
conv, # type: ignore[arg-type]
|
||||
conv,
|
||||
tool_message_v2_content=v2_content,
|
||||
)
|
||||
# User message (no forwarded entry) still goes through the
|
||||
@@ -597,7 +597,7 @@ class TestConversationToMelody:
|
||||
]
|
||||
}
|
||||
out = _conversation_to_melody_messages(
|
||||
conv, # type: ignore[arg-type]
|
||||
conv,
|
||||
tool_message_v2_content=v2_content,
|
||||
)
|
||||
assert out[0]["content"] == [
|
||||
@@ -607,7 +607,7 @@ class TestConversationToMelody:
|
||||
def test_tool_message_v2_content_none_falls_back_to_default(self):
|
||||
conv = [{"role": "tool", "tool_call_id": "c", "content": "plain text"}]
|
||||
out = _conversation_to_melody_messages(
|
||||
conv, # type: ignore[arg-type]
|
||||
conv,
|
||||
tool_message_v2_content=None,
|
||||
)
|
||||
assert out[0]["content"] == [{"type": "text", "text": "plain text"}]
|
||||
@@ -626,7 +626,7 @@ class TestBuildRenderConfig:
|
||||
# Bare kwargs -> cmd4 (the current Command A+ prompt format).
|
||||
# Mirrors ``_DEFAULT_FORMAT`` in ``vllm/renderers/cohere.py`` and
|
||||
# the ``--cohere-format`` CLI default.
|
||||
fmt, cfg = _build_render_config(self._conv(), {}) # type: ignore[arg-type]
|
||||
fmt, cfg = _build_render_config(self._conv(), {})
|
||||
assert fmt == "cmd4"
|
||||
assert cfg["use_jinja"] is True
|
||||
assert isinstance(cfg["messages"], list)
|
||||
@@ -634,12 +634,12 @@ class TestBuildRenderConfig:
|
||||
assert "additional_template_fields" not in cfg
|
||||
|
||||
def test_explicit_cmd3(self):
|
||||
fmt, cfg = _build_render_config(self._conv(), {"cohere_format": "cmd3"}) # type: ignore[arg-type]
|
||||
fmt, cfg = _build_render_config(self._conv(), {"cohere_format": "cmd3"})
|
||||
assert fmt == "cmd3"
|
||||
|
||||
def test_invalid_format_raises(self):
|
||||
with pytest.raises(ValueError, match="Invalid cohere_format"):
|
||||
_build_render_config(self._conv(), {"cohere_format": "cmd5"}) # type: ignore[arg-type]
|
||||
_build_render_config(self._conv(), {"cohere_format": "cmd5"})
|
||||
|
||||
def test_documents_converted(self):
|
||||
_, cfg = _build_render_config(
|
||||
@@ -650,7 +650,7 @@ class TestBuildRenderConfig:
|
||||
{"id": "d1", "data": {"text": "wrapped"}},
|
||||
]
|
||||
},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert cfg["documents"] == [
|
||||
{"text": "doc text"},
|
||||
{"id": "d1", "text": "wrapped"},
|
||||
@@ -665,7 +665,7 @@ class TestBuildRenderConfig:
|
||||
{"type": "function", "function": {"name": "preferred"}}
|
||||
],
|
||||
},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
names = [t["name"] for t in cfg["available_tools"]]
|
||||
assert names == ["preferred"]
|
||||
|
||||
@@ -673,30 +673,30 @@ class TestBuildRenderConfig:
|
||||
_, cfg = _build_render_config(
|
||||
self._conv(),
|
||||
{"tools": [{"type": "function", "function": {"name": "from_tools"}}]},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert [t["name"] for t in cfg["available_tools"]] == ["from_tools"]
|
||||
|
||||
@pytest.mark.parametrize("value", ["enabled", "disabled"])
|
||||
def test_reasoning_type_direct(self, value):
|
||||
_, cfg = _build_render_config(self._conv(), {"reasoning_type": value}) # type: ignore[arg-type]
|
||||
_, cfg = _build_render_config(self._conv(), {"reasoning_type": value})
|
||||
assert cfg["reasoning_type"] == value
|
||||
|
||||
def test_thinking_dict_shorthand_resolves_reasoning_type(self):
|
||||
_, cfg = _build_render_config(self._conv(), {"thinking": {"type": "enabled"}}) # type: ignore[arg-type]
|
||||
_, cfg = _build_render_config(self._conv(), {"thinking": {"type": "enabled"}})
|
||||
assert cfg["reasoning_type"] == "enabled"
|
||||
|
||||
def test_thinking_shorthand_ignores_unknown_type(self):
|
||||
_, cfg = _build_render_config(self._conv(), {"thinking": {"type": "auto"}}) # type: ignore[arg-type]
|
||||
_, cfg = _build_render_config(self._conv(), {"thinking": {"type": "auto"}})
|
||||
assert "reasoning_type" not in cfg
|
||||
|
||||
def test_dev_instruction_forwarded(self):
|
||||
_, cfg = _build_render_config(self._conv(), {"dev_instruction": "be brief"}) # type: ignore[arg-type]
|
||||
_, cfg = _build_render_config(self._conv(), {"dev_instruction": "be brief"})
|
||||
assert cfg["dev_instruction"] == "be brief"
|
||||
|
||||
def test_response_format_json_object_sets_json_mode(self):
|
||||
_, cfg = _build_render_config(
|
||||
self._conv(), {"response_format": {"type": "json_object"}}
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert cfg["json_mode"] is True
|
||||
assert "json_schema" not in cfg
|
||||
|
||||
@@ -705,7 +705,7 @@ class TestBuildRenderConfig:
|
||||
_, cfg = _build_render_config(
|
||||
self._conv(),
|
||||
{"response_format": {"type": "json_schema", "schema": schema}},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
# JSON-encoded for melody (string-only schema field).
|
||||
assert cfg["json_schema"] == json.dumps(schema)
|
||||
|
||||
@@ -721,35 +721,35 @@ class TestBuildRenderConfig:
|
||||
"schema": {"schema": inner},
|
||||
}
|
||||
},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert cfg["json_schema"] == json.dumps(inner)
|
||||
|
||||
def test_json_schema_kwarg_direct(self):
|
||||
# Caller can also pass ``json_schema`` directly, both as dict and
|
||||
# as a pre-stringified value.
|
||||
_, cfg = _build_render_config(self._conv(), {"json_schema": {"a": 1}}) # type: ignore[arg-type]
|
||||
_, cfg = _build_render_config(self._conv(), {"json_schema": {"a": 1}})
|
||||
assert cfg["json_schema"] == '{"a": 1}'
|
||||
_, cfg = _build_render_config(
|
||||
self._conv(), {"json_schema": "raw-string-schema"}
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert cfg["json_schema"] == "raw-string-schema"
|
||||
|
||||
def test_json_mode_kwarg_overrides(self):
|
||||
_, cfg = _build_render_config(self._conv(), {"json_mode": True}) # type: ignore[arg-type]
|
||||
_, cfg = _build_render_config(self._conv(), {"json_mode": True})
|
||||
assert cfg["json_mode"] is True
|
||||
|
||||
def test_cmd3_safety_mode_lowercased(self):
|
||||
_, cfg = _build_render_config(
|
||||
self._conv(),
|
||||
{"cohere_format": "cmd3", "safety_mode": "CONTEXTUAL"},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert cfg["safety_mode"] == "contextual"
|
||||
|
||||
def test_cmd3_citation_quality_direct(self):
|
||||
_, cfg = _build_render_config(
|
||||
self._conv(),
|
||||
{"cohere_format": "cmd3", "citation_quality": "ACCURATE"},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert cfg["citation_quality"] == "accurate"
|
||||
|
||||
def test_cmd3_citation_quality_derived_from_citation_options(self):
|
||||
@@ -758,20 +758,20 @@ class TestBuildRenderConfig:
|
||||
_, cfg = _build_render_config(
|
||||
self._conv(),
|
||||
{"cohere_format": "cmd3", "citation_options": {"mode": "accurate"}},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert cfg["citation_quality"] == "on"
|
||||
|
||||
_, cfg = _build_render_config(
|
||||
self._conv(),
|
||||
{"cohere_format": "cmd3", "citation_options": {"mode": "off"}},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert cfg["citation_quality"] == "off"
|
||||
|
||||
def test_cmd3_skip_preamble_forwarded(self):
|
||||
_, cfg = _build_render_config(
|
||||
self._conv(),
|
||||
{"cohere_format": "cmd3", "skip_preamble": True},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert cfg["skip_preamble"] is True
|
||||
|
||||
def test_cmd3_no_grounding_field(self):
|
||||
@@ -779,7 +779,7 @@ class TestBuildRenderConfig:
|
||||
_, cfg = _build_render_config(
|
||||
self._conv(),
|
||||
{"cohere_format": "cmd3", "grounding": "fast"},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert "grounding" not in cfg
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -800,7 +800,7 @@ class TestBuildRenderConfig:
|
||||
_, cfg = _build_render_config(
|
||||
self._conv(),
|
||||
{"cohere_format": "cmd4", "grounding": raw},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert cfg["grounding"] == expected
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -818,7 +818,7 @@ class TestBuildRenderConfig:
|
||||
"cohere_format": "cmd4",
|
||||
"citation_options": {"mode": mode},
|
||||
},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert cfg["grounding"] == expected
|
||||
|
||||
def test_cmd4_grounding_rejects_unknown_value(self):
|
||||
@@ -826,7 +826,7 @@ class TestBuildRenderConfig:
|
||||
_build_render_config(
|
||||
self._conv(),
|
||||
{"cohere_format": "cmd4", "grounding": "foobar"},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
def test_cmd4_platform_instruction(self):
|
||||
_, cfg = _build_render_config(
|
||||
@@ -835,7 +835,7 @@ class TestBuildRenderConfig:
|
||||
"cohere_format": "cmd4",
|
||||
"platform_instruction": "do this",
|
||||
},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert cfg["platform_instruction"] == "do this"
|
||||
|
||||
def test_cmd4_no_safety_mode_field(self):
|
||||
@@ -847,7 +847,7 @@ class TestBuildRenderConfig:
|
||||
"safety_mode": "contextual",
|
||||
"citation_quality": "on",
|
||||
},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert "safety_mode" not in cfg
|
||||
assert "citation_quality" not in cfg
|
||||
|
||||
@@ -862,7 +862,7 @@ class TestBuildRenderConfig:
|
||||
"my_var": "x",
|
||||
"documents": ["doc"], # consumed, must NOT leak through
|
||||
},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
extras = cfg["additional_template_fields"]
|
||||
assert extras == {"reasoning_effort": "low", "my_var": "x"}
|
||||
# Sanity: the consumed key still produced its dedicated config slot.
|
||||
@@ -875,7 +875,7 @@ class TestBuildRenderConfig:
|
||||
_, cfg = _build_render_config(
|
||||
self._conv(),
|
||||
{"template_id": "tpl1"},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert cfg["template_id"] == "tpl1"
|
||||
# use_jinja is always True, regardless of caller input.
|
||||
assert cfg["use_jinja"] is True
|
||||
@@ -896,7 +896,7 @@ class TestBuildRenderConfig:
|
||||
_build_render_config(
|
||||
self._conv(),
|
||||
{cohere_only_key: "raw {{ jinja }}"},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize("cohere_only_key", ["template_jinja", "template"])
|
||||
def test_cohere_only_template_kwargs_none_is_tolerated(self, cohere_only_key):
|
||||
@@ -906,7 +906,7 @@ class TestBuildRenderConfig:
|
||||
_, cfg = _build_render_config(
|
||||
self._conv(),
|
||||
{cohere_only_key: None},
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert cohere_only_key not in cfg
|
||||
assert "additional_template_fields" not in cfg
|
||||
|
||||
@@ -918,7 +918,7 @@ class TestBuildRenderConfig:
|
||||
self._conv(),
|
||||
{},
|
||||
"raw {{ jinja }}",
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert cfg["template_jinja"] == "raw {{ jinja }}"
|
||||
assert cfg["use_jinja"] is True
|
||||
|
||||
@@ -927,7 +927,7 @@ class TestBuildRenderConfig:
|
||||
self._conv(),
|
||||
{},
|
||||
None,
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
assert "template_jinja" not in cfg
|
||||
|
||||
def test_tool_message_v2_content_key_picked_up_from_kwargs(self):
|
||||
@@ -954,7 +954,7 @@ class TestBuildRenderConfig:
|
||||
]
|
||||
}
|
||||
}
|
||||
_, cfg = _build_render_config(conv, kwargs) # type: ignore[arg-type]
|
||||
_, cfg = _build_render_config(conv, kwargs)
|
||||
tool_msg = cfg["messages"][1]
|
||||
assert tool_msg["content"] == [{"type": "document", "document": {"r": "k"}}]
|
||||
# And the key must be *consumed* -- not surfaced as a stray
|
||||
|
||||
@@ -139,7 +139,7 @@ class TestValidatePrompt:
|
||||
|
||||
with pytest.raises(TypeError, match="should be a list of integers"):
|
||||
renderer.render_prompts(
|
||||
_preprocess_prompt(renderer.model_config, [[1, 2], ["foo", "bar"]]) # type: ignore[arg-type]
|
||||
_preprocess_prompt(renderer.model_config, [[1, 2], ["foo", "bar"]])
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user