| name | python-workflow |
| version | 1.0.0 |
| status | implemented |
| description | Python 项目工作流增强 - 覆盖 Python 特有的开发模式、测试工具和常见陷阱
自动叠加到 agentic-workflow 上,提供语言专属指导
|
| tags | ["language","python","workflow"] |
| requires | {"tools":["Bash","Read","Write","Grep"]} |
PYTHON WORKFLOW
Overview
当检测到 Python 项目时(存在 pyproject.toml / setup.py / *.py),此 skill 的规则叠加在 agentic-workflow 之上。
Python 项目检测
test -f pyproject.toml && echo "Python/pyproject"
test -f setup.py && echo "Python/setuptools"
test -f requirements.txt && echo "Python/requirements"
Iron Laws(Python 专属)
NO TYPE HINTS = REJECT — 新函数必须有类型注解(Python 3.9+ 用 from __future__ import annotations)
NO BARE EXCEPT — 禁止裸 except:,必须捕获具体异常类型
NO MUTABLE DEFAULTS — 禁止 def f(x=[]) 模式,用 None 替代
NO SILENT FAILURES — 禁止空 except pass,必须记录或重抛
EXECUTING 阶段 — Python 规范
代码质量强制检查
python3 -m ruff check . --fix
python3 -m mypy . --ignore-missing-imports
python3 -m pytest tests/ -q
Python 3.9 兼容性(本项目要求)
from __future__ import annotations
def process(items: list[str] | None = None) -> dict[str, Any]:
...
def process(items: list[str] | None = None) -> dict[str, Any]:
测试框架
python3 -m pytest tests/ -v --tb=long
python3 -m pytest tests/ -q --tb=short
python3 -m pytest tests/ -k "test_name"
python3 -m pytest --cov=scripts --cov-report=term-missing
DEBUGGING 阶段 — Python 专属诊断
python3 -m pytest --tb=long -q 2>&1 | tail -60
python3 -m ruff check . 2>&1 | head -30
python3 -c "import sys; print(sys.version)"
pip list | grep -E "pytest|ruff|mypy" | head -10
常见 Python 陷阱
| 问题 | 症状 | 修复 |
|---|
| `list | None` 类型语法错误 | TypeError: unsupported operand |
| 循环导入 | ImportError: cannot import name | 检查 __init__.py,使用延迟导入 |
| 可变默认参数 | 多次调用结果累积 | 改为 = None,函数内 if x is None: x = [] |
| Mock 未重置 | 测试间状态泄漏 | 使用 @pytest.fixture(autouse=True) 清理 |
assert 被优化掉 | -O 模式 assert 无效 | 用 if not condition: raise ValueError |
REVIEWING 阶段 — Python 专属清单
除标准 REVIEWING 清单外,额外检查:
包管理最佳实践
pip install -e ".[dev]"
python3 -c "import scripts; print('OK')"