Merged
Conversation
Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat>
Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat>
Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat>
Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat>
Contributor
There was a problem hiding this comment.
Hey - 我发现了 1 个问题,并留下了一些整体性的反馈:
- 在
MessageSession中,platform_id现在被设为field(init=False),但仍在__str__中使用;建议添加一个__post_init__或专门的工厂/初始化函数,以确保在任何字符串化之前都已设置该字段,从而避免运行时出现AttributeError。 - 在
FishAudioTTSAPISource中,将默认model从None修改为空字符串会改变set_model的行为;请再次确认""是否与之前的None情况等价处理,并且不会触发意外的模型选择或错误。 - 在
dynamic_callback的回退路径中,当ctx.channel为None时,你可能需要显式记录日志或追踪该分支,因为这很可能是异常场景,有助于诊断某些缺失频道信息的异常 Discord 上下文。
给 AI Agent 的提示词
Please address the comments from this code review:
## Overall Comments
- In `MessageSession`, `platform_id` is now `field(init=False)` but still used in `__str__`; consider adding a `__post_init__` or dedicated factory/initializer to guarantee it is set before any stringification to avoid runtime `AttributeError`.
- The change in `FishAudioTTSAPISource` from `None` to an empty string for the default `model` may alter `set_model` behavior; double-check that `""` is handled equivalently to the previous `None` case and won’t trigger unexpected model selection or errors.
- In the `dynamic_callback` fallback path where `ctx.channel` is `None`, you might want to log or trace this branch explicitly since it is likely exceptional and could help diagnose odd Discord contexts where channel details are missing.
## Individual Comments
### Comment 1
<location> `astrbot/core/platform/message_session.py:16` </location>
<code_context>
message_type: MessageType
session_id: str
- platform_id: str | None = None
+ platform_id: str = field(init=False)
def __str__(self):
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `field(init=False)` for `platform_id` makes the attribute potentially missing at runtime when `__str__` is called.
Because `platform_id` is `init=False`, it won’t exist on instances created via the dataclass `__init__`, yet `__str__` always accesses `self.platform_id`. Any code that prints/logs a `MessageSession` before manually setting `platform_id` will now get an `AttributeError` instead of a `None` value. Please either keep a default (e.g. `platform_id: str | None = None`) or initialize it in `__post_init__`/a custom constructor so it’s always set before use.
</issue_to_address>帮我变得更有用!请对每条评论点选 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- In
MessageSession,platform_idis nowfield(init=False)but still used in__str__; consider adding a__post_init__or dedicated factory/initializer to guarantee it is set before any stringification to avoid runtimeAttributeError. - The change in
FishAudioTTSAPISourcefromNoneto an empty string for the defaultmodelmay alterset_modelbehavior; double-check that""is handled equivalently to the previousNonecase and won’t trigger unexpected model selection or errors. - In the
dynamic_callbackfallback path wherectx.channelisNone, you might want to log or trace this branch explicitly since it is likely exceptional and could help diagnose odd Discord contexts where channel details are missing.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `MessageSession`, `platform_id` is now `field(init=False)` but still used in `__str__`; consider adding a `__post_init__` or dedicated factory/initializer to guarantee it is set before any stringification to avoid runtime `AttributeError`.
- The change in `FishAudioTTSAPISource` from `None` to an empty string for the default `model` may alter `set_model` behavior; double-check that `""` is handled equivalently to the previous `None` case and won’t trigger unexpected model selection or errors.
- In the `dynamic_callback` fallback path where `ctx.channel` is `None`, you might want to log or trace this branch explicitly since it is likely exceptional and could help diagnose odd Discord contexts where channel details are missing.
## Individual Comments
### Comment 1
<location> `astrbot/core/platform/message_session.py:16` </location>
<code_context>
message_type: MessageType
session_id: str
- platform_id: str | None = None
+ platform_id: str = field(init=False)
def __str__(self):
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `field(init=False)` for `platform_id` makes the attribute potentially missing at runtime when `__str__` is called.
Because `platform_id` is `init=False`, it won’t exist on instances created via the dataclass `__init__`, yet `__str__` always accesses `self.platform_id`. Any code that prints/logs a `MessageSession` before manually setting `platform_id` will now get an `AttributeError` instead of a `None` value. Please either keep a default (e.g. `platform_id: str | None = None`) or initialize it in `__post_init__`/a custom constructor so it’s always set before use.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Soulter
approved these changes
Feb 5, 2026
LIghtJUNction
added a commit
that referenced
this pull request
Feb 5, 2026
* 默认host修改为::,同时新增两个环境变量DASHBOARD_HOST,DASHBOARD_ENABLE,和DASHBOARD_PORT对齐 * feat: systemd support (#4880) * fix: pyright lint (#4874) * feat: 将 MessageSession 的 platform_id 改为 init=False,实例化时无需传入 Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * refactor: 将 isinstance 检查改为元组、将默认模型值设为空字符串、将类型注解改为 Any 并导入 * refactor: 为 _serialize_job 增加返回类型注解 dict * fix: 使用 cast 获取百度 AIP 的 msg 并对 psutil_addr 引入 type: ignore Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * refactor: 引入 _AddrWithPort 协议并替换 conn.laddr 的 cast Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * fix: 在构建 AstrBotMessage 时对 ctx.channel 可能为 None 进行兜底处理 Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> --------- Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * fix: TypeError when MCP schema type is a list (#4867) * Fix TypeError when MCP schema type is a list Fixes crash in Gemini native tools with VRChat MCP. * Refactor: avoid modifying schema in place per feedback * Fix formatting and cleanup comments * docs: update watashiwakoseinodesukara Removed duplicate text and added a new image. * 修复/跨平台一致性 * 琐事/类型标注和一些简单错误修正 * 修复/检查端口时候包含ipv6 * 修复/enable变量的赋值逻辑 --------- Co-authored-by: Dt8333 <25431943+Dt8333@users.noreply.github.com> Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> Co-authored-by: boushi1111 <95118141+boushi1111@users.noreply.github.com> Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>
united-pooh
pushed a commit
to united-pooh/AstrBot
that referenced
this pull request
Feb 19, 2026
* feat: 将 MessageSession 的 platform_id 改为 init=False,实例化时无需传入 Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * refactor: 将 isinstance 检查改为元组、将默认模型值设为空字符串、将类型注解改为 Any 并导入 * refactor: 为 _serialize_job 增加返回类型注解 dict * fix: 使用 cast 获取百度 AIP 的 msg 并对 psutil_addr 引入 type: ignore Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * refactor: 引入 _AddrWithPort 协议并替换 conn.laddr 的 cast Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * fix: 在构建 AstrBotMessage 时对 ctx.channel 可能为 None 进行兜底处理 Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> --------- Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat>
miaoxutao123
pushed a commit
to miaoxutao123/AstrBot
that referenced
this pull request
Feb 28, 2026
* 默认host修改为::,同时新增两个环境变量DASHBOARD_HOST,DASHBOARD_ENABLE,和DASHBOARD_PORT对齐 * feat: systemd support (AstrBotDevs#4880) * fix: pyright lint (AstrBotDevs#4874) * feat: 将 MessageSession 的 platform_id 改为 init=False,实例化时无需传入 Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * refactor: 将 isinstance 检查改为元组、将默认模型值设为空字符串、将类型注解改为 Any 并导入 * refactor: 为 _serialize_job 增加返回类型注解 dict * fix: 使用 cast 获取百度 AIP 的 msg 并对 psutil_addr 引入 type: ignore Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * refactor: 引入 _AddrWithPort 协议并替换 conn.laddr 的 cast Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * fix: 在构建 AstrBotMessage 时对 ctx.channel 可能为 None 进行兜底处理 Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> --------- Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * fix: TypeError when MCP schema type is a list (AstrBotDevs#4867) * Fix TypeError when MCP schema type is a list Fixes crash in Gemini native tools with VRChat MCP. * Refactor: avoid modifying schema in place per feedback * Fix formatting and cleanup comments * docs: update watashiwakoseinodesukara Removed duplicate text and added a new image. * 修复/跨平台一致性 * 琐事/类型标注和一些简单错误修正 * 修复/检查端口时候包含ipv6 * 修复/enable变量的赋值逻辑 --------- Co-authored-by: Dt8333 <25431943+Dt8333@users.noreply.github.com> Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> Co-authored-by: boushi1111 <95118141+boushi1111@users.noreply.github.com> Co-authored-by: Soulter <37870767+Soulter@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 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.
RT,修复pyright报错。
Modifications / 改动点
用field标注platform_id,避免声明None.
添加兜底,适配py-cord>=2.7.0同时保证前向兼容.
修改部分default值和声明
Screenshots or Test Results / 运行截图或测试结果
0 errors, 0 warnings, 0 informations
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.Summary by Sourcery
修复了 Discord 适配器、仪表盘路由、内容安全策略、消息会话以及 provider 源模块中的 Pyright 类型检查问题。
Bug 修复:
any注解改为使用Any。增强:
platform_id设为非可选字段,并通过 dataclass 的 field metadata 进行初始化。Original summary in English
Summary by Sourcery
Fix Pyright type-checking issues across Discord adapter, dashboard routes, content safety strategy, message session, and provider source modules.
Bug Fixes:
Enhancements: