fix(openai): import Union so litellm is importable again - #35710
Closed
Classic298 wants to merge 1 commit into
Closed
fix(openai): import Union so litellm is importable again#35710Classic298 wants to merge 1 commit into
Classic298 wants to merge 1 commit into
Conversation
owns_wrapped_http_client annotates its parameter Optional[Union[...]] but Union was never imported, so the annotation is evaluated at class creation and import litellm raises NameError on every Python version that evaluates annotations eagerly, which is 3.10 through 3.13. ruff check litellm reports it as F821 on a clean checkout
This was referenced Aug 3, 2026
Contributor
Author
Contributor
Greptile SummaryThis PR restores LiteLLM imports by adding the missing
Confidence Score: 5/5The PR appears safe to merge because it supplies the missing standard-library typing symbol without changing runtime behavior beyond restoring module importability The isolated import addition resolves the existing annotation lookup failure and introduces no new execution, state, dependency, or security behavior
|
| Filename | Overview |
|---|---|
| litellm/llms/openai/common_utils.py | Adds the missing Union typing import required by an existing annotation; no issues identified |
Reviews (1): Last reviewed commit: "fix(openai): import Union so litellm is ..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
Problem this solves:
import litellmraises NameError on Python 3.10 to 3.13Unionis used in an annotation but never importedruff check litellmreports it as F821How it solves it:
Unionto the existing typing importRelevant issues
Linear ticket
Pre-Submission checklist
No test added on purpose: any test that imports litellm is the regression test, and there are thousands of them. The gap is that something is letting a red
ruff check litellmthrough, since F821 already names this exact lineScreenshots / Proof of Fix
owns_wrapped_http_client, added in #35492, annotates its parameterOptional[Union[httpx.Client, httpx.AsyncClient]]. The annotation is evaluated when the class body runs, so the missing name is not a typing nit, it kills the import outright on every version that evaluates annotations eagerlyBefore, on
litellm_internal_stagingat 9d5984b:python -c "import litellm"After, same commands on this branch:
ruff check litellmprintsAll checks passed!,import litellmsucceeds, and a completion round tripsType
🐛 Bug Fix
Changes
Unionjoins the existingfrom typing import (...)block inlitellm/llms/openai/common_utils.pyFinal Attestation