fix: parse fx resize y scale argument #58

Merged
Passthem merged 1 commits from pi-agent/konabot:fix/fx-resize-arg-parsing into master 2026-03-14 01:27:41 +08:00
Contributor

PR Type

Bug fix, Tests


Description

  • 修复 apply_resize 方法参数类型提示

  • 新增测试用例验证参数解析逻辑

  • 确保缩放功能 Y 轴参数正确识别


Diagram Walkthrough

flowchart LR
  Input["用户输入命令"] --> Parse["解析参数"]
  Parse --> Func["apply_resize"]
  Func --> Type["类型验证"]

File Walkthrough

Relevant files
Bug fix
fx_handle.py
完善缩放方法类型定义                                                                                             

konabot/plugins/fx_process/fx_handle.py

  • 更新 apply_resize 方法签名
  • scale_y 参数添加 float 类型提示
  • 增强代码类型安全性
+1/-1     
Tests
test_fx_process.py
增加参数解析测试用例                                                                                             

tests/test_fx_process.py

  • 新增 test_prase_input_args_parses_resize_second_argument_as_float
  • 验证缩放参数被解析为浮点数
  • 确保参数解析逻辑正确
+15/-0   

### **PR Type** Bug fix, Tests ___ ### **Description** - 修复 `apply_resize` 方法参数类型提示 - 新增测试用例验证参数解析逻辑 - 确保缩放功能 Y 轴参数正确识别 ___ ### Diagram Walkthrough ```mermaid flowchart LR Input["用户输入命令"] --> Parse["解析参数"] Parse --> Func["apply_resize"] Func --> Type["类型验证"] ``` <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix</strong></td><td><table> <tr> <td> <details> <summary><strong>fx_handle.py</strong><dd><code>完善缩放方法类型定义</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> konabot/plugins/fx_process/fx_handle.py - 更新 `apply_resize` 方法签名 - 为 `scale_y` 参数添加 `float` 类型提示 - 增强代码类型安全性 </details> </td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/fix/fx-resize-arg-parsing/konabot/plugins/fx_process/fx_handle.py">+1/-1</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>test_fx_process.py</strong><dd><code>增加参数解析测试用例</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> tests/test_fx_process.py <ul><li>新增 <code>test_prase_input_args_parses_resize_second_argument_as_float</code><br> <li> 验证缩放参数被解析为浮点数<br> <li> 确保参数解析逻辑正确</ul> </details> </td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/fix/fx-resize-arg-parsing/tests/test_fx_process.py">+15/-0</a>&nbsp; &nbsp; </td> </tr> </table></td></tr></tr></tbody></table> </details> ___
pi-agent added 1 commit 2026-03-14 01:26:37 +08:00
Passthem requested review from Passthem 2026-03-14 01:27:15 +08:00
Passthem approved these changes 2026-03-14 01:27:34 +08:00
Passthem merged commit e86a385448 into master 2026-03-14 01:27:41 +08:00
Collaborator

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵
🧪 PR contains tests
🔒 Security concerns

 Recommended focus areas for review

类型提示准确性

参数 scale_y 的默认值为 None,但类型提示声明为 float。建议修改为 Optional[float]float | None 以准确反映类型约束。

def apply_resize(image: Image.Image, scale: float = 1.5, scale_y: float = None) -> Image.Image:
拼写错误

测试函数名 test_prase_input_args_parses_resize_second_argument_as_float 中存在拼写错误,prase 应修正为 parse

def test_prase_input_args_parses_resize_second_argument_as_float():
    filters = prase_input_args("缩放 2 3")

    assert len(filters) == 1
    assert filters[0].name == "缩放"
    assert filters[0].args == [2.0, 3.0]
## PR Reviewer Guide 🔍 Here are some key observations to aid the review process: <table> <tr><td>⏱️&nbsp;<strong>Estimated effort to review</strong>: 1 🔵⚪⚪⚪⚪</td></tr> <tr><td>🧪&nbsp;<strong>PR contains tests</strong></td></tr> <tr><td>🔒&nbsp;<strong>Security concerns</strong><br><br> 无</td></tr> <tr><td>⚡&nbsp;<strong>Recommended focus areas for review</strong><br><br> <details><summary><a href='https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/fix/fx-resize-arg-parsing/konabot/plugins/fx_process/fx_handle.py#L196-L196'><strong>类型提示准确性</strong></a> 参数 `scale_y` 的默认值为 `None`,但类型提示声明为 `float`。建议修改为 `Optional[float]` 或 `float | None` 以准确反映类型约束。 </summary> ```python def apply_resize(image: Image.Image, scale: float = 1.5, scale_y: float = None) -> Image.Image: ``` </details> <details><summary><a href='https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/fix/fx-resize-arg-parsing/tests/test_fx_process.py#L83-L88'><strong>拼写错误</strong></a> 测试函数名 `test_prase_input_args_parses_resize_second_argument_as_float` 中存在拼写错误,`prase` 应修正为 `parse`。 </summary> ```python def test_prase_input_args_parses_resize_second_argument_as_float(): filters = prase_input_args("缩放 2 3") assert len(filters) == 1 assert filters[0].name == "缩放" assert filters[0].args == [2.0, 3.0] ``` </details> </td></tr> </table>
Collaborator

PR Code Suggestions

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
修正参数类型提示以允许 None 值

类型提示 scale_y: float = None 是不正确的,因为 None 不是 float 类型。这会导致静态类型检查器报错。应使用 float | None
Optional[float] 来明确表示该参数可以接受 None 值。

konabot/plugins/fx_process/fx_handle.py [196]

-def apply_resize(image: Image.Image, scale: float = 1.5, scale_y: float = None) -> Image.Image:
+def apply_resize(image: Image.Image, scale: float = 1.5, scale_y: float | None = None) -> Image.Image:
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies that scale_y: float = None is invalid for type checkers since None is not a float. Fixing it to float | None improves type safety and prevents static analysis errors, though it does not affect runtime behavior.

Low
## PR Code Suggestions ✨ <!-- 5e0e39b --> Explore these optional code suggestions: <table><thead><tr><td><strong>Category</strong></td><td align=left><strong>Suggestion&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </strong></td><td align=center><strong>Impact</strong></td></tr><tbody><tr><td rowspan=1>General</td> <td> <details><summary>修正参数类型提示以允许 None 值</summary> ___ **类型提示 <code>scale_y: float = None</code> 是不正确的,因为 <code>None</code> 不是 <code>float</code> 类型。这会导致静态类型检查器报错。应使用 <code>float | None</code> <br>或 <code>Optional[float]</code> 来明确表示该参数可以接受 <code>None</code> 值。** [konabot/plugins/fx_process/fx_handle.py [196]](https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/fix/fx-resize-arg-parsing/konabot/plugins/fx_process/fx_handle.py#L196-L196) ```diff -def apply_resize(image: Image.Image, scale: float = 1.5, scale_y: float = None) -> Image.Image: +def apply_resize(image: Image.Image, scale: float = 1.5, scale_y: float | None = None) -> Image.Image: ``` <details><summary>Suggestion importance[1-10]: 6</summary> __ Why: The suggestion correctly identifies that `scale_y: float = None` is invalid for type checkers since `None` is not a `float`. Fixing it to `float | None` improves type safety and prevents static analysis errors, though it does not affect runtime behavior. </details></details></td><td align=center>Low </td></tr></tr></tbody></table>
Sign in to join this conversation.
No description provided.