Skip to content

refactor: convert isinstance chains to match/case syntax#36862

Merged
asukaminato0721 merged 3 commits into
langgenius:mainfrom
krishkantiuj-ren:refactor-isinstance-to-match-case
Jun 1, 2026
Merged

refactor: convert isinstance chains to match/case syntax#36862
asukaminato0721 merged 3 commits into
langgenius:mainfrom
krishkantiuj-ren:refactor-isinstance-to-match-case

Conversation

@krishkantiuj-ren
Copy link
Copy Markdown
Contributor

Description

Convert if isinstance/elif isinstance chains to Python 3.10+ structural pattern matching (match/case) for better readability and exhaustive type checking.

Changes

  • api/core/logging/filters.py: Convert Account/EndUser type dispatch to match/case
  • api/core/app/apps/base_app_queue_manager.py: Convert dict/list/DeclarativeMeta check to match/case
  • api/core/rag/retrieval/dataset_retrieval.py: Convert str/int/float/list/tuple patterns to match/case

Related Issues

Refs #35902

krishkantiuj-ren 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
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. refactor labels May 31, 2026
@asukaminato0721 asukaminato0721 enabled auto-merge May 31, 2026 11:51
@asukaminato0721 asukaminato0721 requested a review from Copilot May 31, 2026 11:52
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 31, 2026

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 45.88% 45.88% 0.00%
Strict coverage 45.40% 45.40% 0.00%
Typed symbols 24,768 24,768 0
Untyped symbols 29,528 29,528 0
Modules 2764 2764 0

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 @override decorators 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.

Comment thread api/core/app/apps/pipeline/generate_response_converter.py
Comment thread api/core/app/apps/base_app_queue_manager.py Outdated
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 1, 2026
@asukaminato0721 asukaminato0721 added this pull request to the merge queue Jun 1, 2026
Merged via the queue into langgenius:main with commit de47d43 Jun 1, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer refactor size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants