Skip to content

fix(openai): import Union so litellm is importable again - #35710

Closed
Classic298 wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
Classic298:fix_missing_union_import
Closed

fix(openai): import Union so litellm is importable again#35710
Classic298 wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
Classic298:fix_missing_union_import

Conversation

@Classic298

@Classic298 Classic298 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • import litellm raises NameError on Python 3.10 to 3.13
  • Union is used in an annotation but never imported
  • ruff check litellm reports it as F821

How it solves it:

  • add Union to the existing typing import

Relevant issues

Linear ticket

Pre-Submission checklist

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review

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 litellm through, since F821 already names this exact line

Screenshots / Proof of Fix

owns_wrapped_http_client, added in #35492, annotates its parameter Optional[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 eagerly

Before, on litellm_internal_staging at 9d5984b:

python -c "import litellm"
  File "litellm/llms/openai/common_utils.py", line 138, in BaseOpenAILLM
    def owns_wrapped_http_client(http_client: Optional[Union[httpx.Client, httpx.AsyncClient]]) -> bool:
                                                       ^^^^^
NameError: name 'Union' is not defined
ruff check litellm
F821 Undefined name `Union`
   --> litellm/llms/openai/common_utils.py:138:56
Found 1 error.

After, same commands on this branch: ruff check litellm prints All checks passed!, import litellm succeeds, and a completion round trips

Type

🐛 Bug Fix

Changes

Union joins the existing from typing import (...) block in litellm/llms/openai/common_utils.py

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

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
@Classic298

Copy link
Copy Markdown
Contributor Author

Relates to : #35709 #35703

@greptile-apps

greptile-apps Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR restores LiteLLM imports by adding the missing typing.Union import used by an eagerly evaluated OpenAI adapter annotation

  • Adds Union to the existing typing import list in common_utils.py
  • Resolves the import-time NameError and Ruff F821 violation

Confidence Score: 5/5

The 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

Important Files Changed

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

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed-hq

codspeed-hq Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing Classic298:fix_missing_union_import (a62d6c0) with litellm_internal_staging (a6d4654)1

Open in CodSpeed

Footnotes

  1. No successful run was found on litellm_internal_staging (32eb072) during the generation of this report, so a6d4654 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Classic298 Classic298 closed this Aug 7, 2026
@Classic298
Classic298 deleted the fix_missing_union_import branch August 7, 2026 11:22
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.

1 participant