# Python 代码风格 (python-code-style)

> 说明 Python 的 lint 与格式化工具配置、PEP 8 命名、导入顺序、类型注解和 Google 风格 docstring 规范。

- 分类: [代码规范](https://www.myskills.tools/zh/categories/code-standards/)
- 来源: 社区 · Seth Hobson
- 代码仓库: https://github.com/wshobson/agents/tree/main/plugins/python-development/skills/python-code-style (commit cbb6049)
- SKILL.md: https://github.com/wshobson/agents/blob/main/plugins/python-development/skills/python-code-style/SKILL.md
- 安装命令: `npx skills add wshobson/agents --skill python-code-style`
- 许可证: MIT
- 兼容工具: Claude Code, Codex, Cursor, Copilot, OpenCode
- 权限: read-repo ✓, write-files ✓, shell ✓, network ✓
- 状态: 扫描通过
- 规则扫描无法覆盖所有风险，安装前请阅读此技能的 SKILL.md，确认权限后再使用。

## 核心规则

格式之争交给工具：一次配置，自动执行。

## 执行阶段

1. **配置工具** — 在 pyproject.toml 中配置 ruff 负责 lint 和格式化，并启用严格模式的 mypy 或 pyright。
2. **命名与导入** — 遵循 PEP 8，名称清晰优先于简短；导入按标准库、第三方、本地分组，只用绝对导入。
3. **类型与文档** — 为所有公共 API 添加类型注解和 Google 风格 docstring，写明 Args、Returns、Raises 和示例。
4. **格式与项目文档** — 行宽设为 120，合理换行；按模板维护 README 和 Keep a Changelog 格式的 CHANGELOG，并在 CI 中运行 linter。

## 权限说明（据 SKILL.md 整理）

| 能力 | 是否需要 | 说明 |
|---|---|---|
| 文件写入 | 需要 | 修改 pyproject.toml 等配置、为代码补充类型和 docstring，并编写项目文档。 |
| 命令执行 | 部分需要 | 运行 ruff check --fix、ruff format 以及安装 ruff、mypy 等工具的命令。 |
| 网络外发 | 部分需要 | 仅在用 pip 安装 ruff、mypy 等工具时访问软件包索引。 |

## SKILL.md 头部信息（YAML）

```yaml
---
name: python-code-style
description: Python code style, linting, formatting, naming conventions, and documentation standards. Use when writing new code, reviewing style, configuring linters, writing docstrings, or establishing project standards.
---
```

首页: https://www.myskills.tools/zh/ · URL: https://www.myskills.tools/zh/skills/python-code-style/
