Skip to content

litellm_fix: refactor base_process_llm_request to fix PLR0915#20125

Closed
shin-bot-litellm wants to merge 2 commits intomainfrom
litellm_fix_ruff_plr0915
Closed

litellm_fix: refactor base_process_llm_request to fix PLR0915#20125
shin-bot-litellm wants to merge 2 commits intomainfrom
litellm_fix_ruff_plr0915

Conversation

@shin-bot-litellm
Copy link
Contributor

Refactors the base_process_llm_request method in Router to fix PLR0915 (too many statements).

Extracts helper methods for cleaner code organization:

  • _prepare_call_context
  • _log_verbose_retry_context
  • _try_model_fallback_from_exception
  • _select_retry_delay_from_headers

The function exceeds the 50 statement limit due to comprehensive request handling logic.
Adding noqa comment as quick fix - refactoring can be done in a separate PR.
- Extract response metadata extraction into _extract_response_metadata helper
- Add ResponseMetadata NamedTuple for type-safe metadata handling
- Use metadata object instead of individual variables to reduce statement count
- Remove noqa: PLR0915 suppression as the function now passes ruff check

This properly addresses the 'too many statements' warning by refactoring
instead of suppressing it.
@vercel
Copy link

vercel bot commented Jan 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Error Error Jan 31, 2026 8:13am

Request Review

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants