-
Couldn't load subscription status.
- Fork 1.2k
fix(mypy): part-02 resolve OpenAI compatibility layer type issues #3947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ashwinb
wants to merge
7
commits into
mypy/01-meta-reference-agents
Choose a base branch
from
mypy/02-openai-compat-layer
base: mypy/01-meta-reference-agents
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix(mypy): part-02 resolve OpenAI compatibility layer type issues #3947
ashwinb
wants to merge
7
commits into
mypy/01-meta-reference-agents
from
mypy/02-openai-compat-layer
+142
−107
Conversation
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
6822dec to
2882ae3
Compare
Resolves 111 mypy errors across OpenAI inference compatibility utilities: litellm_openai_mixin.py (23 errors → 1 unavoidable): - Add type annotation for input_dict parameter - Fix JsonSchemaResponseFormat dict conversion and manipulation - Add None checks for tool_config access with walrus operator - Fix get_api_key() to properly handle None key_field - Add model_store None checks in all three OpenAI methods - Add type annotations for provider_resource_id variable - Add type: ignore for litellm external library returns openai_compat.py (88 errors → 0): - Add None checks for TopPSamplingStrategy temperature and top_p - Add type: ignore for no-any-return in text_from_choice - Fix union-attr errors in logprobs iteration with None checks - Add None checks for choice.text and finish_reason - Fix OpenAICompatCompletionChoice.message attribute access - Filter tool_calls to only valid ToolCall objects - Add type annotations for converted_messages and choices lists - Fix TypedDict ** expansion issues in message conversions - Add type: ignore for function dict index operations - Fix tool_choice and response_format type conversions - Add type annotations for lls_tools variable - Fix sampling strategy assignment with proper ordering - Add None checks for buffer string concatenations - Rename shadowed tool_call variable to parsed_tool_call - Fix message content and tool_calls type conversions - Add isinstance checks before attribute access on content - Fix OpenAI finish_reason type literal conversions Code remains clean and readable with strategic use of type: ignore pragmas only where necessary for external library compatibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
6d3f196 to
a8d51a1
Compare
ashwinb
commented
Oct 28, 2025
src/llama_stack/providers/utils/inference/litellm_openai_mixin.py
Outdated
Show resolved
Hide resolved
ashwinb
commented
Oct 28, 2025
ashwinb
commented
Oct 28, 2025
ashwinb
commented
Oct 28, 2025
ashwinb
commented
Oct 28, 2025
- Simplify provider_resource_id assignment with assertion (review comment 1) - Fix comment placement order (review comment 2) - Refactor tool_calls list building to avoid union-attr suppression (review comment 3) - Rename response_format to response_format_dict to avoid shadowing (review comment 4) - Update type: ignore comments for message.content with accurate explanation of OpenAI SDK type alias resolution issue (review comment 5) - Add assertions in litellm_openai_mixin to validate provider_resource_id is not None 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Changed comment from "message.content uses list[AliasType] but mypy expects Iterable[BaseType]" to "OpenAI SDK uses aliased types internally that mypy sees as incompatible with base types". This is more accurate - the OpenAI SDK's message parameter types use aliased names (like OpenAIChatCompletionContentPartTextParam) internally in their type annotations, and mypy cannot match these with base type names (ChatCompletionContentPartTextParam) even though they're the same types at runtime. Verified that importing and using base types directly doesn't resolve the issue because the SDK's internal type annotations still use the aliased names. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…rors" This reverts commit b8ac194.
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.
Summary
Fixes 111 mypy type errors in OpenAI compatibility layer (PR3 in mypy remediation series).
Changes:
litellm_openai_mixin.py: Added type annotations, None checks for tool_config/model_store accessopenai_compat.py: Added None checks throughout, fixed TypedDict expansions, proper type conversions for messages/tool_callsResult: 23 → 1 errors in litellm file, 88 → 0 errors in openai_compat file