refactor: convert isinstance chains to match/case syntax#36862
Merged
asukaminato0721 merged 3 commits intoJun 1, 2026
Merged
Conversation
added 2 commits
May 31, 2026 15:32
…teResponseConverter Add @OverRide decorators to all 4 methods that override parent class methods: - convert_blocking_full_response - convert_blocking_simple_response - convert_stream_full_response - convert_stream_simple_response Refs langgenius#36406
Convert if isinstance/elif isinstance chains to Python 3.10+ structural pattern matching (match/case) for better readability and exhaustive type checking. Files changed: - api/core/logging/filters.py: Account/EndUser type dispatch - api/core/app/apps/base_app_queue_manager.py: dict/list/DeclarativeMeta check - api/core/rag/retrieval/dataset_retrieval.py: str/int/float/list/tuple patterns Refs langgenius#35902
Contributor
Pyrefly Type Coverage
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors several isinstance dispatch paths to Python structural pattern matching, aligning with the codebase’s Python 3.12 support and existing use of match/case.
Changes:
- Converts metadata filtering and invoke-result content handling type checks to
match/case. - Converts identity extraction and queue SQLAlchemy-model checks to
match/case. - Adds
@overridedecorators to the pipeline response converter methods.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
api/core/rag/retrieval/dataset_retrieval.py |
Refactors type-dependent metadata filter handling and invoke-result content accumulation. |
api/core/logging/filters.py |
Refactors account/end-user identity extraction dispatch. |
api/core/app/apps/base_app_queue_manager.py |
Refactors recursive dict/list SQLAlchemy model detection dispatch. |
api/core/app/apps/pipeline/generate_response_converter.py |
Adds @override annotations to converter overrides. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
asukaminato0721
approved these changes
Jun 1, 2026
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.
Description
Convert
if isinstance/elif isinstancechains to Python 3.10+ structural pattern matching (match/case) for better readability and exhaustive type checking.Changes
Account/EndUsertype dispatch tomatch/casedict/list/DeclarativeMetacheck tomatch/casestr/int/float/list/tuplepatterns tomatch/caseRelated Issues
Refs #35902