Skip to content

refactor: port some if else to match#31841

Merged
asukaminato0721 merged 19 commits into
langgenius:mainfrom
asukaminato0721:match-3
May 11, 2026
Merged

refactor: port some if else to match#31841
asukaminato0721 merged 19 commits into
langgenius:mainfrom
asukaminato0721:match-3

Conversation

@asukaminato0721
Copy link
Copy Markdown
Contributor

@asukaminato0721 asukaminato0721 commented Feb 2, 2026

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

part of #30001

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods

@asukaminato0721 asukaminato0721 marked this pull request as ready for review February 2, 2026 13:33
Copilot AI review requested due to automatic review settings February 2, 2026 13:33
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 2, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @asukaminato0721, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on a significant code refactoring effort across several Python files. The primary goal is to modernize the codebase by replacing various if/elif/else conditional statements with Python's match/case construct. This change enhances the readability, maintainability, and potentially the extensibility of the code, particularly in areas dealing with multiple distinct conditions such as data source types, file extensions, and workflow node types.

Highlights

  • Code Refactoring to Match/Case Statements: Conditional logic across multiple Python files has been refactored from traditional if/elif/else blocks to the more modern and readable match/case statements. This improves code clarity and maintainability.
  • Enhanced Data Source Handling: The api/controllers/console/datasets/datasets.py file now uses match/case for handling different data source types (upload_file, notion_import, website_crawl), streamlining the logic for creating ExtractSetting objects.
  • Improved Workflow Tracing Logic: In api/core/ops/arize_phoenix_trace/arize_phoenix_trace.py, the determination of OpenInference span kinds based on workflow node types has been updated to use match/case with the NodeType enum, making the code more explicit and robust.
  • Streamlined Data Extraction Logic: The api/core/rag/extractor/extract_processor.py file has undergone significant refactoring, converting complex nested if/elif/else structures for datasource_type and file_extension into match/case statements, which simplifies the file extraction process.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Feb 2, 2026
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 multiple Python files to replace if/elif/else chains with Python 3.10+ match/case statements for improved readability and maintainability.

Changes:

  • Converted conditional chains to match/case statements across 7 files
  • Added NodeType enum import in arize_phoenix_trace.py to support enum-based matching
  • Nested match statements appropriately for complex conditional logic

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
api/core/rag/extractor/extract_processor.py Refactored datasource type and file extension conditionals to nested match statements
api/core/rag/datasource/vdb/opensearch/opensearch_vector.py Converted authentication method selection to match statement
api/core/prompt/simple_prompt_transform.py Refactored special variable key handling to match statement
api/core/ops/weave_trace/entities/weave_trace_entity.py Converted field name conditionals to match statement in validator
api/core/ops/langsmith_trace/entities/langsmith_trace_entity.py Converted field name conditionals to match statement in validator
api/core/ops/arize_phoenix_trace/arize_phoenix_trace.py Refactored node type conditionals to match statement with NodeType enum import
api/controllers/console/datasets/datasets.py Converted data source type conditionals to match statement

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/core/ops/arize_phoenix_trace/arize_phoenix_trace.py Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors several files to use Python's match/case statement instead of if/elif/else chains. The changes improve code readability and are well-implemented. I've found one minor point of improvement for code clarity. Overall, this is a good refactoring effort.

Comment thread api/core/ops/arize_phoenix_trace/arize_phoenix_trace.py Outdated
Copilot AI review requested due to automatic review settings February 5, 2026 09:37

This comment was marked as outdated.

Copilot AI review requested due to automatic review settings February 14, 2026 17:02
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

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/services/dataset_service.py Outdated
Comment thread api/services/dataset_service.py Outdated
Comment thread api/services/dataset_service.py Outdated
Comment thread api/services/dataset_service.py Outdated
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

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/controllers/console/datasets/datasets.py
Copilot AI review requested due to automatic review settings March 4, 2026 06:35
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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread api/services/dataset_service.py Outdated
Comment thread api/core/ops/weave_trace/entities/weave_trace_entity.py Outdated
Comment thread api/core/rag/extractor/extract_processor.py Outdated
Comment thread api/core/rag/extractor/extract_processor.py Outdated
@langgenius langgenius deleted a comment from github-actions Bot May 11, 2026
@langgenius langgenius deleted a comment from github-actions Bot May 11, 2026
@asukaminato0721 asukaminato0721 changed the title refactor: port api/controllers/console/datasets/datasets.py api/core/ops/arize_phoenix_trace/arize_phoenix_trace.py api/core/ops/langsmith_trace/entities/langsmith_trace_entity.py api/core/ops/weave_trace/entities/weave_trace_entity.py api/core/prompt/simple_prompt_transform.py api/core/rag/datasource/vdb/opensearch/opensearch_vector.py api/core/rag/extractor/extract_processor.py to match refactor: port some if else to match May 11, 2026
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels May 11, 2026
@langgenius langgenius deleted a comment from github-actions Bot May 11, 2026
@langgenius langgenius deleted a comment from github-actions Bot May 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 0.00% 43.74% +43.74%
Strict coverage 0.00% 43.26% +43.26%
Typed symbols 0 21,996 +21,996
Untyped symbols 0 28,603 +28,603
Modules 0 2548 +2,548

@asukaminato0721 asukaminato0721 enabled auto-merge May 11, 2026 05:16
@langgenius langgenius deleted a comment from github-actions Bot May 11, 2026
@langgenius langgenius deleted a comment from github-actions Bot May 11, 2026
@asukaminato0721 asukaminato0721 added this pull request to the merge queue May 11, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 11, 2026
Merged via the queue into langgenius:main with commit d625ac0 May 11, 2026
27 checks passed
@asukaminato0721 asukaminato0721 deleted the match-3 branch May 11, 2026 06:49
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:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants