style(anthropic): fix black formatting in normalize_system_role diff

Pure formatting changes to satisfy the lint gate:
- common_utils.py: collapse one-line dict literal
- handler.py: collapse one-line function-call assignment
- test_normalize_system_role.py: reformat multiline assertions,
  add blank line after nested import, fix missing trailing newline

No logic changes. All 13 normalize_system_role tests still pass.
This commit is contained in:
sanjibani 2026-06-20 11:23:05 +05:30
parent c5d360fa9f
commit 7111c8412a
3 changed files with 12 additions and 14 deletions

View file

@ -1033,9 +1033,7 @@ def normalize_system_role_in_anthropic_messages(
elif content is not None and not isinstance(content, str):
# Best-effort: stringify unknown content shapes so callers
# don't silently lose information.
promoted_blocks.append(
{"type": "text", "text": str(content)}
)
promoted_blocks.append({"type": "text", "text": str(content)})
else:
kept.append(m)

View file

@ -411,9 +411,7 @@ def anthropic_messages_handler(
# role." OpenAI-style clients routinely send the system prompt as
# messages[0]; lift those up to the top-level `system` parameter so
# sync callers (litellm.messages.create) stay valid too. See #30705.
messages, system = normalize_system_role_in_anthropic_messages(
messages, system
)
messages, system = normalize_system_role_in_anthropic_messages(messages, system)
metadata = validate_anthropic_api_metadata(metadata)

View file

@ -40,9 +40,7 @@ class TestNormalizeSystemRole:
new_messages, new_system = normalize_system_role_in_anthropic_messages(
messages, system=None
)
assert new_system == [
{"type": "text", "text": "you are a helpful assistant"}
]
assert new_system == [{"type": "text", "text": "you are a helpful assistant"}]
assert new_messages == [{"role": "user", "content": "hi"}]
def test_promotes_content_block_system_message(self):
@ -221,6 +219,7 @@ class TestSyncPathNormalization:
from litellm.llms.anthropic.common_utils import (
normalize_system_role_in_anthropic_messages as real_normalize,
)
return real_normalize(messages, system)
# Patch the symbol the handler imported.
@ -242,9 +241,9 @@ class TestSyncPathNormalization:
finally:
handler_module.normalize_system_role_in_anthropic_messages = original
assert len(calls) >= 1, (
"sync handler did not invoke normalize_system_role_in_anthropic_messages"
)
assert (
len(calls) >= 1
), "sync handler did not invoke normalize_system_role_in_anthropic_messages"
def test_sync_handler_skips_normalizer_when_presanitized_flag_set(self):
"""
@ -260,11 +259,14 @@ class TestSyncPathNormalization:
calls = []
def spy_normalize(messages, system=None): # pragma: no cover - patched at runtime
def spy_normalize(
messages, system=None
): # pragma: no cover - patched at runtime
calls.append((list(messages), system))
from litellm.llms.anthropic.common_utils import (
normalize_system_role_in_anthropic_messages as real_normalize,
)
return real_normalize(messages, system)
original = handler_module.normalize_system_role_in_anthropic_messages
@ -288,4 +290,4 @@ class TestSyncPathNormalization:
if __name__ == "__main__":
sys.exit(pytest.main([__file__, "-v"]))
sys.exit(pytest.main([__file__, "-v"]))