Fix mypy regression: TypedDict key error in fireworks_ai transformation - #20391
Merged
Conversation
Cast message to dict before calling pop() to satisfy mypy's type checker. The message is typed as a Union of TypedDicts which don't have the 'provider_specific_fields' key, but the runtime check already confirms it's a dict with this key.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Shin seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Contributor
Greptile OverviewGreptile SummaryThis PR fixes a mypy type error introduced in PR #20334. The error occurred because The fix adds
This is a minimal, type-safe fix that resolves the mypy regression without changing runtime behavior. Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/llms/fireworks_ai/chat/transformation.py | Added cast(dict, message) to fix mypy type error when calling .pop() on AllMessageValues union type |
Sequence Diagram
sequenceDiagram
participant Caller
participant FireworksAIConfig
participant TypeChecker as mypy Type Checker
Caller->>FireworksAIConfig: _transform_messages_helper(messages)
Note over FireworksAIConfig: messages: List[AllMessageValues]
loop For each message
FireworksAIConfig->>FireworksAIConfig: Check if isinstance(message, dict)
FireworksAIConfig->>FireworksAIConfig: Check if "provider_specific_fields" in message
alt Has provider_specific_fields
Note over FireworksAIConfig,TypeChecker: Before fix: message.pop() fails type check
Note over FireworksAIConfig,TypeChecker: After fix: cast(dict, message).pop() passes
FireworksAIConfig->>FireworksAIConfig: cast(dict, message).pop("provider_specific_fields", None)
end
end
FireworksAIConfig-->>Caller: Return cleaned messages
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
Cast message to dict before calling pop() to satisfy mypy's type checker. The message is typed as a Union of TypedDicts which don't have the 'provider_specific_fields' key, but the runtime check already confirms it's a dict with this key.
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.
Regression Fix
Failing Job:
mypy_lintingCaused By: #20334 (commit 3765d88)
Author: @sameer-berri
What Broke
PR #20334 added code to remove
provider_specific_fieldsfrom messages before sending to FireworksAI. The code callsmessage.pop("provider_specific_fields", None)wheremessageis typed asAllMessageValues(a Union of TypedDicts).mypy correctly complained that none of the TypedDicts in the union have a
provider_specific_fieldskey:This Fix
Cast
messagetodictbefore callingpop(). This is safe because:isinstance(message, dict)before reaching this line"provider_specific_fields" in messagebefore poppingThis is consistent with line 239 which already uses
cast(dict, message)forfilter_value_from_dict().