pre-commit script wrongly report SyntaxError for match statement #11347

Closed
opened 2026-02-21 18:58:37 -05:00 by yindo · 0 comments
Owner

Originally created by @QuantumGhost on GitHub (Mar 17, 2025).

Originally assigned to: @QuantumGhost on GitHub.

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

N/A

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

Summary

How to reproduce:

  • Change some Python code
  • Add it and commit it, the husky pre-commit hook will run and output some errors like the following:
api/tests/integration_tests/workflow/nodes/__mock/code_executor.py:17:9: SyntaxError: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)
   |
15 |     def invoke(cls, language: Literal["python3", "javascript", "jinja2"], code: str, inputs: dict) -> dict:
16 |         # invoke directly
17 |         match language:
   |         ^^^^^
18 |             case CodeLanguage.PYTHON3:
19 |                 return {"result": 3}
   |

The problem is that ruff v0.9.10 does not use the requires-python configuration in pyproject.toml.
If we run ruff with --verbose flag, it would output the following logs:

[2025-03-14][16:56:03][ruff_workspace::pyproject][DEBUG] `project.requires_python` in `pyproject.toml` will not be use
d to set `target_version` when using `ruff.toml`.

Upstream issue in Ruff: https://github.com/astral-sh/ruff/pull/16319

Proposed solutions

The bug above is fixed in Ruff v0.11.0, so upgrading ruff to v0.11.0 is a solution. There is already a PR for it: #15952.

Another solution is adding target-version = "py311" to .ruff.toml.

✔️ Expected Behavior

Ruff exits without any error.

Actual Behavior

Ruff reports SyntaxError: Cannot use match statement on Python 3.9.

Originally created by @QuantumGhost on GitHub (Mar 17, 2025). Originally assigned to: @QuantumGhost on GitHub. ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version N/A ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce ## Summary How to reproduce: - Change some Python code - Add it and commit it, the `husky` pre-commit hook will run and output some errors like the following: ```text api/tests/integration_tests/workflow/nodes/__mock/code_executor.py:17:9: SyntaxError: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10) | 15 | def invoke(cls, language: Literal["python3", "javascript", "jinja2"], code: str, inputs: dict) -> dict: 16 | # invoke directly 17 | match language: | ^^^^^ 18 | case CodeLanguage.PYTHON3: 19 | return {"result": 3} | ``` The problem is that ruff v0.9.10 does not use the `requires-python` configuration in `pyproject.toml`. If we run ruff with `--verbose` flag, it would output the following logs: ```text [2025-03-14][16:56:03][ruff_workspace::pyproject][DEBUG] `project.requires_python` in `pyproject.toml` will not be use d to set `target_version` when using `ruff.toml`. ``` Upstream issue in Ruff: https://github.com/astral-sh/ruff/pull/16319 ## Proposed solutions The bug above is fixed in Ruff v0.11.0, so upgrading ruff to v0.11.0 is a solution. There is already a PR for it: #15952. Another solution is adding `target-version = "py311"` to `.ruff.toml`. ### ✔️ Expected Behavior Ruff exits without any error. ### ❌ Actual Behavior Ruff reports `SyntaxError: Cannot use `match` statement on Python 3.9`.
yindo added the 🐞 bug label 2026-02-21 18:58:37 -05:00
yindo closed this issue 2026-02-21 18:58:37 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#11347