-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: missing 2 required positional arguments: 'filter1' and 'filter2'
#4840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - 我发现了 1 个问题,并且留下了一些整体性的反馈:
CustomFilterAnd.__init__中的错误信息仍然包含拼写错误CustomFilter lass;请将其与CustomFilterOr中已修正的错误信息保持一致。- 考虑将
CustomFilterOr和CustomFilterAnd中重复的isinstance逻辑(以及可能在register_custom_filter中的检查)抽取到一个共享的辅助函数或公共的基础校验逻辑中,以避免重复并降低未来出现不一致的风险。
供 AI 代理使用的提示词
Please address the comments from this code review:
## Overall Comments
- The error message in `CustomFilterAnd.__init__` still contains the typo `CustomFilter lass`; align it with the corrected message used in `CustomFilterOr`.
- Consider consolidating the repeated isinstance logic for `CustomFilterOr` and `CustomFilterAnd` (and possibly the check in `register_custom_filter`) into a shared helper or a common base validation to avoid duplication and reduce the risk of future inconsistencies.
## Individual Comments
### Comment 1
<location> `astrbot/core/star/filter/custom_filter.py:40` </location>
<code_context>
def __init__(self, filter1: CustomFilter, filter2: CustomFilter):
super().__init__()
- if not isinstance(filter1, CustomFilter | CustomFilterAnd | CustomFilterOr):
+ if not isinstance(filter1, (CustomFilter, CustomFilterAnd, CustomFilterOr)):
raise ValueError(
- "CustomFilter lass can only operate with other CustomFilter.",
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Only `filter1` is validated, which may allow unsupported types in `filter2`.
Both `CustomFilterOr` and `CustomFilterAnd` validate only `filter1`. If `filter2` should meet the same constraints, apply the same `isinstance` check there to prevent invalid filter combinations at runtime.
Suggested implementation:
```python
if not isinstance(filter1, (CustomFilter, CustomFilterAnd, CustomFilterOr)) or not isinstance(
filter2, (CustomFilter, CustomFilterAnd, CustomFilterOr)
):
```
```python
if not isinstance(filter1, (CustomFilter, CustomFilterAnd, CustomFilterOr)) or not isinstance(
filter2, (CustomFilter, CustomFilterAnd, CustomFilterOr)
):
```
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据这些反馈改进后续的评审。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- The error message in
CustomFilterAnd.__init__still contains the typoCustomFilter lass; align it with the corrected message used inCustomFilterOr. - Consider consolidating the repeated isinstance logic for
CustomFilterOrandCustomFilterAnd(and possibly the check inregister_custom_filter) into a shared helper or a common base validation to avoid duplication and reduce the risk of future inconsistencies.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The error message in `CustomFilterAnd.__init__` still contains the typo `CustomFilter lass`; align it with the corrected message used in `CustomFilterOr`.
- Consider consolidating the repeated isinstance logic for `CustomFilterOr` and `CustomFilterAnd` (and possibly the check in `register_custom_filter`) into a shared helper or a common base validation to avoid duplication and reduce the risk of future inconsistencies.
## Individual Comments
### Comment 1
<location> `astrbot/core/star/filter/custom_filter.py:40` </location>
<code_context>
def __init__(self, filter1: CustomFilter, filter2: CustomFilter):
super().__init__()
- if not isinstance(filter1, CustomFilter | CustomFilterAnd | CustomFilterOr):
+ if not isinstance(filter1, (CustomFilter, CustomFilterAnd, CustomFilterOr)):
raise ValueError(
- "CustomFilter lass can only operate with other CustomFilter.",
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Only `filter1` is validated, which may allow unsupported types in `filter2`.
Both `CustomFilterOr` and `CustomFilterAnd` validate only `filter1`. If `filter2` should meet the same constraints, apply the same `isinstance` check there to prevent invalid filter combinations at runtime.
Suggested implementation:
```python
if not isinstance(filter1, (CustomFilter, CustomFilterAnd, CustomFilterOr)) or not isinstance(
filter2, (CustomFilter, CustomFilterAnd, CustomFilterOr)
):
```
```python
if not isinstance(filter1, (CustomFilter, CustomFilterAnd, CustomFilterOr)) or not isinstance(
filter2, (CustomFilter, CustomFilterAnd, CustomFilterOr)
):
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| def __init__(self, filter1: CustomFilter, filter2: CustomFilter): | ||
| super().__init__() | ||
| if not isinstance(filter1, CustomFilter | CustomFilterAnd | CustomFilterOr): | ||
| if not isinstance(filter1, (CustomFilter, CustomFilterAnd, CustomFilterOr)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): 目前只对 filter1 进行了校验,这可能会让不受支持的类型出现在 filter2 中。
CustomFilterOr 和 CustomFilterAnd 都只会校验 filter1。如果 filter2 也应满足相同约束,请在它上面应用同样的 isinstance 检查,以避免在运行时出现无效的过滤器组合。
建议实现:
if not isinstance(filter1, (CustomFilter, CustomFilterAnd, CustomFilterOr)) or not isinstance(
filter2, (CustomFilter, CustomFilterAnd, CustomFilterOr)
): if not isinstance(filter1, (CustomFilter, CustomFilterAnd, CustomFilterOr)) or not isinstance(
filter2, (CustomFilter, CustomFilterAnd, CustomFilterOr)
):Original comment in English
suggestion (bug_risk): Only filter1 is validated, which may allow unsupported types in filter2.
Both CustomFilterOr and CustomFilterAnd validate only filter1. If filter2 should meet the same constraints, apply the same isinstance check there to prevent invalid filter combinations at runtime.
Suggested implementation:
if not isinstance(filter1, (CustomFilter, CustomFilterAnd, CustomFilterOr)) or not isinstance(
filter2, (CustomFilter, CustomFilterAnd, CustomFilterOr)
): if not isinstance(filter1, (CustomFilter, CustomFilterAnd, CustomFilterOr)) or not isinstance(
filter2, (CustomFilter, CustomFilterAnd, CustomFilterOr)
):
fixes: #4777
Modifications / 改动点
Screenshots or Test Results / 运行截图或测试结果
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.由 Sourcery 提供的总结
修复自定义过滤器的验证和注册逻辑,避免在组合或注册它们时出现运行时错误。
错误修复:
isinstance元组形式,从而在使用自定义过滤器时防止无效参数错误。增强项:
CustomFilter类。Original summary in English
Summary by Sourcery
Fix validation and registration of custom filters to avoid runtime errors when composing or registering them.
Bug Fixes:
Enhancements: