Skip to content

refactor: reduce cyclomatic complexity (30 functions exceed threshold of 20) #201

@Oaklight

Description

@Oaklight

Background

Complexipy was added to pre-commit in commit 10644a8 but is currently suspended because 30 functions in the codebase exceed the complexity threshold of 20.

The hook will be re-enabled once these are resolved:

entry: complexipy src/llm_rosetta tests -e _vendor -mx 20

Violations (sorted by complexity, descending)

Function Complexity
fix_orphaned_tool_calls (openai_chat/tool_ops) 43
_Socks5Handler::_do_handshake (tests/gateway) 40
sanitize_request_data (gateway/logging) 38
OpenAIChatMessageOps::_unpack_tool_content 37
_stream_event_generator (gateway/proxy) 37
fix_orphaned_tool_calls_ir 36
OpenAIResponsesToolOps::ir_tool_call_to_p 33
GoogleGenAIMessageOps::_reconcile_tool_call_ids 33
sanitize_schema 30
_proxy_handler (gateway/app) 30
OpenAIResponsesToolOps::p_tool_call_to_ir 30
_collect_ir_tool_ids 30
OpenAIResponsesMessageOps::p_messages_to_ir 29
OpenAIResponsesConverter::_capture_preserve_metadata 29
OpenAIResponsesConverter::_apply_preserve_metadata 29
OpenAIChatMessageOps::_reorder_tool_messages 29
fix_orphaned_tool_calls (openai_responses/tool_ops) 26
fetch_upstream_models (gateway/admin/routes/config) 26
GoogleGenAIConverter::stream_response_from_provider 25
GoogleGenAIConverter::request_to_provider 25
call_api_stream (tests/integration, ×2) 25
OpenAIChatConverter::_handle_tool_calls_from_p 24
create_auth_hook (gateway/auth) 24
AnthropicConverter::request_to_provider 24
GoogleGenAIMessageOps::_p_message_to_ir 23
GatewayConfig::__init__ (gateway/config) 22
fix_orphaned_tool_calls (anthropic/tool_ops) 22
AnthropicConverter::request_from_provider 22
GoogleGenAIContentOps::p_part_to_ir 21

Definition of done

  • All functions reduced to complexity ≤ 20 (ideally ≤ 15)
  • Complexipy hook re-enabled in .pre-commit-config.yaml
  • pre-commit run complexipy --all-files exits 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Priority 2: MediumrefactorCode refactoring and cleanup

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions