refactor: convert isinstance chains to match/case pattern#36364
Conversation
- services/tools/tools_transform_service.py: repack_provider() method - services/rag_pipeline/rag_pipeline.py: datasource parameter handling - core/tools/tool_label_manager.py: get_tool_labels() method - core/memory/token_buffer_memory.py: content type handling Improves code readability and follows modern Python 3.10+ patterns. Addresses issue #35902
Pyrefly Type Coverage
|
|
@dosu how about this pr |
|
This PR looks good overall. It's Part 4 of the systematic Strengths:
One thing to watch:
No red flags — this is a clean, low-risk refactor that follows patterns already approved and merged in earlier parts of this series. To reply, just mention @dosu. Share context across your team and agents. Try Dosu. |
There was a problem hiding this comment.
Pull request overview
This PR refactors several isinstance/elif chains into Python 3.10+ match/case statements to make type-branching logic more declarative and consistent across the codebase.
Changes:
- Refactored provider repacking logic to use
match/casefor dict/entity/provider variants. - Refactored datasource parameter value branching (None/str/list/other) to
match/case. - Refactored controller/content type branching in tool label and memory prompt-building code to
match/case.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| api/services/tools/tools_transform_service.py | Refactors provider-type branching in repack_provider() using match/case. |
| api/services/rag_pipeline/rag_pipeline.py | Refactors datasource parameter handling to match/case while preserving assignment behavior. |
| api/core/tools/tool_label_manager.py | Refactors controller-type branching in get_tool_labels() to match/case. |
| api/core/memory/token_buffer_memory.py | Refactors prompt content type handling (text/image) to match/case. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
This PR refactors multiple chains to use Python's pattern (introduced in Python 3.10), improving code readability and maintainability.
Changes
Files Modified
services/tools/tools_transform_service.py
services/rag_pipeline/rag_pipeline.py
core/tools/tool_label_manager.py
core/memory/token_buffer_memory.py
Benefits
Testing
#35902