fix: python 3.10 typing compatibility in compact editor and claude 3 cache pricing (#38076, #38056) - #38189
Conversation
|
|
Greptile SummaryThis PR adds a version-compatible
Confidence Score: 4/5The PR appears safe to merge, with non-blocking improvements needed in Python 3.10 regression coverage and test-comment cleanup. The implementation and synchronized pricing updates have no established runtime defect, while the accepted findings concern an unexercised compatibility-test branch and redundant comments. Files Needing Attention: tests/test_litellm/llms/anthropic/experimental_pass_through/context_management/test_compact_typing_compatibility.py; tests/test_litellm/test_claude_3_cache_pricing.py
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/experimental_pass_through/context_management/editors/compact.py | Selects NotRequired from typing on Python 3.11+ and typing_extensions on older supported runtimes; no concrete implementation defect was identified. |
| model_prices_and_context_window.json | Corrects the Claude 3 Haiku and Opus above-one-hour cache-creation rates in the canonical model-cost map. |
| litellm/model_prices_and_context_window_backup.json | Mirrors the same corrected rates in the packaged backup map. |
| tests/test_litellm/llms/anthropic/experimental_pass_through/context_management/test_compact_typing_compatibility.py | Adds import and TypedDict checks, but the standard Python 3.12 workflow cannot exercise the Python 3.10 fallback branch. |
| tests/test_litellm/test_claude_3_cache_pricing.py | Verifies both pricing maps, with two redundant comments that violate the repository’s source-comment convention. |
Reviews (1): Last reviewed commit: "fix: python 3.10 typing compatibility in..." | Re-trigger Greptile
| if sys.version_info >= (3, 11): | ||
| import typing | ||
|
|
||
| assert compact_module.NotRequired is typing.NotRequired | ||
| else: | ||
| import typing_extensions | ||
|
|
||
| assert compact_module.NotRequired is typing_extensions.NotRequired |
There was a problem hiding this comment.
The test selects its assertion from the interpreter running pytest, while the standard unit workflow uses Python 3.12. As a result, the newly added typing_extensions.NotRequired fallback is not exercised there, so a Python 3.10 compatibility regression would not be caught by this test.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| assert model in prices, f"{model} not found in {path}" | ||
| model_info = prices[model] | ||
|
|
||
| input_cost = model_info["input_cost_per_token"] |
There was a problem hiding this comment.
This comment and the equivalent Opus comment merely restate the immediately following input_cost * 2 calculations. Removing both avoids duplicated prose that can become stale and follows the repository convention of reserving source comments for complex logic, tool directives, or TODO/FIXME items.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Description
This PR resolves two issues:
Issue [Bug]: import litellm fails on Python 3.10 — NotRequired imported from stdlib typing without fallback #38076: Python 3.10 typing compatibility in
compact.pylitellm/llms/anthropic/experimental_pass_through/context_management/editors/compact.py,NotRequiredwas imported directly fromtyping, which causes anImportErroron Python < 3.11.NotRequiredfromtypingon Python >= 3.11 and fallback totyping_extensionson Python < 3.11.Issue [Bug]: claude-3-haiku and claude-3-opus have the Sonnet 1-hour cache write price (12x over / 5x under) #38056: Claude 3 cache creation pricing above 1hr
cache_creation_input_token_cost_above_1hrinmodel_prices_and_context_window.jsonandmodel_prices_and_context_window_backup.json:claude-3-haiku-20240307:5e-07(2x input cost2.5e-07, was incorrectly set to6e-06)claude-3-opus-20240229:3e-05(2x input cost1.5e-05, was incorrectly set to6e-06)Tests
tests/test_litellm/llms/anthropic/experimental_pass_through/context_management/test_compact_typing_compatibility.pytests/test_litellm/test_claude_3_cache_pricing.pymodel_prices_and_context_window.schema.json.