Skip to content

Add utils module docstring - #27255

Closed
oss-agent-shin wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
oss-agent-shin:cursor/add-utils-docstring-efdc
Closed

Add utils module docstring#27255
oss-agent-shin wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
oss-agent-shin:cursor/add-utils-docstring-efdc

Conversation

@oss-agent-shin

Copy link
Copy Markdown
Contributor

Summary

litellm/utils.py did not have a module docstring, so ast.get_docstring() returned None. Added a tiny one-line module docstring and a focused regression test that parses the file and asserts the docstring value.

Repro

On the starting ref (litellm_internal_staging), run:

python3 - <<'PY_REPRO'
import ast
from pathlib import Path
path = Path('litellm/utils.py')
module = ast.parse(path.read_text())
docstring = ast.get_docstring(module)
print(f'{path}: module docstring = {docstring!r}')
if docstring is None:
    raise SystemExit('missing module docstring')
PY_REPRO

Observed before the fix:

litellm/utils.py: module docstring = None
missing module docstring

Evidence

Could not create the requested gist-hosted screenshot/GIF URL because $SHIN_GITHUB_TOKEN does not have the required gist scope (HTTP 404: Not Found ... This API operation needs the "gist" scope). Fallback terminal transcript:

$ python3 -m pytest tests/test_litellm/test_utils_module_docstring.py -vv
============================= test session starts ==============================
platform linux -- Python 3.12.3, pytest-9.0.3, pluggy-1.6.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /workspace
configfile: pyproject.toml
plugins: anyio-4.13.0
collecting ... collected 1 item

tests/test_litellm/test_utils_module_docstring.py::test_utils_module_has_docstring PASSED [100%]

======================== 1 passed, 2 warnings in 0.15s =========================

$ python3 - <<'PY_VERIFY'
import ast
from pathlib import Path
path = Path('litellm/utils.py')
module = ast.parse(path.read_text())
docstring = ast.get_docstring(module)
print(f'{path}: module docstring = {docstring!r}')
if docstring is None:
    raise SystemExit('missing module docstring')
PY_VERIFY
litellm/utils.py: module docstring = 'Utility helpers for LiteLLM core request handling and provider support.'

Tests

  • python3 -m black --target-version py312 litellm/utils.py tests/test_litellm/test_utils_module_docstring.py - passed, no changes.
  • python3 -m pytest tests/test_litellm/test_utils_module_docstring.py -vv - passed (1 passed).
  • python3 -m pytest -x -q - attempted full suite; collection stops in existing cookbook/litellm_router_load_test/test_loadtest_openai_client.py because Azure OpenAI credentials are not configured (Missing credentials... AZURE_OPENAI_API_KEY or AZURE_OPENAI_AD_TOKEN).

Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>
@CLAassistant

Copy link
Copy Markdown

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.

@greptile-apps

greptile-apps Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a one-line module docstring to litellm/utils.py so that ast.get_docstring() returns a meaningful string instead of None, and introduces a focused regression test to verify it.

  • The docstring placement is valid Python — module docstrings are explicitly permitted before from __future__ import annotations — but the existing inline comment on that import line now mischaracterizes the ordering and should be updated.
  • The regression test asserts the exact docstring text rather than just its presence, making it brittle to any future rewording of the docstring.

Confidence Score: 4/5

Safe to merge; both changed files are low-risk and the docstring addition has no runtime impact.

The docstring change is cosmetic and correct. The test guards a real invariant but will break unnecessarily on any future rewording of the docstring, and the inline comment in utils.py is now misleading. Neither issue affects runtime behavior.

The test file tests/test_litellm/test_utils_module_docstring.py would benefit from a less brittle assertion before merging.

Important Files Changed

Filename Overview
litellm/utils.py Adds a one-line module docstring; the only concern is the now-stale inline comment on line 3 about from __future__ import annotations.
tests/test_litellm/test_utils_module_docstring.py New regression test that verifies the module docstring exists; fragile because it asserts the exact docstring text instead of just checking for a non-None value.

Reviews (1): Last reviewed commit: "Add utils module docstring" | Re-trigger Greptile

Comment on lines +9 to +11
assert ast.get_docstring(module) == (
"Utility helpers for LiteLLM core request handling and provider support."
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The test asserts the exact docstring text rather than just checking that one exists. Any future rewording or expansion of the docstring (e.g., adding sentences) will break this test even though the fix it guards against — None being returned — has not regressed. Checking is not None (or that it is a non-empty string) would make the test durable to routine doc updates.

Suggested change
assert ast.get_docstring(module) == (
"Utility helpers for LiteLLM core request handling and provider support."
)
assert ast.get_docstring(module) is not None

Comment thread litellm/utils.py
@@ -1,3 +1,5 @@
"""Utility helpers for LiteLLM core request handling and provider support."""

# from __future__ import annotations must be the first non-comment statement

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Now that a module docstring precedes the __future__ import, the inline comment is no longer accurate — a docstring is itself a statement (an expression statement), so from __future__ import annotations is no longer "the first non-comment statement." Python's grammar explicitly allows module docstrings before __future__ imports, but the comment should reflect the new reality to avoid confusing future readers.

Suggested change
# from __future__ import annotations must be the first non-comment statement
# from __future__ import annotations must appear immediately after the module docstring

oss-pr-review-agent-shin Bot added a commit that referenced this pull request May 6, 2026
@oss-pr-review-agent-shin

Copy link
Copy Markdown
Contributor

🤖 litellm-agent: Merged into staging branch litellm_agent_oss_staging_05_06_2026. Staging PR: #27256


Triage Summary
Adds a module-level docstring to litellm/utils.py and a corresponding AST-based test that asserts the docstring is present and matches the expected string. The change is minimal: two lines added to utils.py and a new 11-line test file. No functional behavior is altered.

Merge Confidence: 5/5 ✅ READY
Ready to ship.

All checks green. Greptile 4/5, no blocking pattern findings, no CircleCI runs (OSS-typical).

oss-pr-review-agent-shin Bot added a commit that referenced this pull request May 6, 2026
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
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