This repository was archived by the owner on Jun 3, 2026. It is now read-only.
🐛 修复 get_message_id 被弃用的问题并简单修缮了代码格式#32
Merged
Merged
Conversation
Contributor
Reviewer's GuideThis PR fixes the deprecated get_message_id usage and applies targeted refactoring and formatting updates across modules, including simplifying plugin reload logic, adding type guards for streaming responses, improving debounce behavior, and minor code annotations. Sequence diagram for plugin file change and reload logic updatesequenceDiagram
participant FileSystemEvent
participant on_plugin_file_change
participant get_plugin
participant reload_plugin
participant context
FileSystemEvent->>on_plugin_file_change: File change event (.py)
on_plugin_file_change->>get_plugin: Search for plugin by name
alt Found package plugin
on_plugin_file_change->>reload_plugin: Reload package plugin
reload_plugin->>context: Reset all context
else Found single-file plugin
on_plugin_file_change->>reload_plugin: Reload single-file plugin
reload_plugin->>context: Reset all context
else Not found
on_plugin_file_change->>on_plugin_file_change: Log not found
end
Class diagram for handler and event message ID updateclassDiagram
class Handler {
- event: Event
- matcher: Matcher
- message_id: str
- target
+ __init__()
...
}
Handler : message_id uses get_message_id(event)
Class diagram for debounce decorator and CodeModifiedHandler updateclassDiagram
class CodeModifiedHandler {
+ on_modified(event: FileSystemEvent)
+ on_created(event)
}
class debounce {
+ decorator(func)
}
CodeModifiedHandler <|-- debounce
Class diagram for process_completion_to_details type guardclassDiagram
class process_completion_to_details {
+ process_completion_to_details(completion: ChatCompletion) -> str
}
process_completion_to_details : type guard for ChatCompletion
process_completion_to_details : returns error string if not ChatCompletion
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- In on_plugin_file_change, the reload logic for package vs single-file plugins is duplicated; consider extracting the common reload+reset steps into a helper to flatten the control flow.
- In process_completion_to_details, returning a plain string for unsupported inputs mixes error and normal flows—consider using an exception or a dedicated result type to distinguish errors cleanly.
- The scattered # type:ignore comments indicate missing or inaccurate type definitions (e.g. delta.reasoning_content); it’d be better to update the type stubs or ChatCompletionChunk model rather than silencing the checks.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In on_plugin_file_change, the reload logic for package vs single-file plugins is duplicated; consider extracting the common reload+reset steps into a helper to flatten the control flow.
- In process_completion_to_details, returning a plain string for unsupported inputs mixes error and normal flows—consider using an exception or a dedicated result type to distinguish errors cleanly.
- The scattered # type:ignore comments indicate missing or inaccurate type definitions (e.g. delta.reasoning_content); it’d be better to update the type stubs or ChatCompletionChunk model rather than silencing the checks.
## Individual Comments
### Comment 1
<location> `nonebot_plugin_marshoai/models.py:119` </location>
<code_context>
spec = importlib.util.spec_from_file_location(
package_name, os.path.join(package_path, "__init__.py")
)
+ assert spec, f"工具包 {package_name} 未找到"
package = importlib.util.module_from_spec(spec)
self.imported_packages[package_name] = package
</code_context>
<issue_to_address>
Using assert for runtime error handling may be inappropriate.
Assert statements can be disabled with Python optimizations, so replace with an explicit exception to guarantee error handling in all environments.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
assert spec, f"工具包 {package_name} 未找到"
=======
if not spec:
raise ImportError(f"工具包 {package_name} 未找到")
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if not (plugin := get_plugin(plugin_name)): | ||
| continue | ||
|
|
||
| if ( |
Contributor
There was a problem hiding this comment.
issue (code-quality): We've found these issues:
- Hoist nested repeated code outside conditional statements (
hoist-similar-statement-from-if) - Hoist repeated code outside conditional statement [×3] (
hoist-statement-from-if)
| @@ -124,7 +125,7 @@ async def handle_single_chat( | |||
|
|
|||
| async def handle_function_call( | |||
| self, | |||
Contributor
There was a problem hiding this comment.
issue (code-quality): We've found these issues:
- Move assignment closer to its usage within a block (
move-assign-in-block) - Merge append into list declaration (
merge-list-append)
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
主要更新:
process_completion_to_details并不支持流式调用的用量获取,这可能需要对流程做一定改动,因此此处未作任何更改)好饿哦
呐呐,陪我出去玩好不好Summary by Sourcery
Fix deprecated API usage and improve code robustness and formatting
Bug Fixes:
Enhancements: