From python
Python核心编码规范与工具链配置。涵盖PEP 8风格、命名约定、代码格式化、uv包管理、ruff检查。适用于编写Python代码、代码风格检查、格式化配置、项目初始化等场景。
npx claudepluginhub lazygophers/ccplugin --plugin pythonThis skill uses the workspace's default tool permissions.
- **python:dev** - 开发阶段使用
Provides Ktor server patterns for routing DSL, plugins (auth, CORS, serialization), Koin DI, WebSockets, services, and testApplication testing.
Conducts multi-source web research with firecrawl and exa MCPs: searches, scrapes pages, synthesizes cited reports. For deep dives, competitive analysis, tech evaluations, or due diligence.
Provides demand forecasting, safety stock optimization, replenishment planning, and promotional lift estimation for multi-location retailers managing 300-800 SKUs.
包管理器:
# ✅ 优先使用 uv(速度提升 10-100 倍)
uv init my-project
uv add fastapi pydantic
# ⚠️ 不推荐:pip(速度慢)
# ⚠️ 可选:poetry(成熟但慢)
代码格式化和 Lint:
# ✅ 推荐:ruff(替代 black + isort + flake8)
ruff format . # 格式化
ruff check --fix . # Lint 并自动修复
# ❌ 已过时:black + isort + flake8 组合
类型检查:
# ✅ 推荐:mypy strict mode
mypy --strict src/
# ⚠️ 可选:pyright(VS Code 集成)
必须遵守:
禁止行为:
i, j, k)# 模块名:lowercase_with_underscores
my_module.py
# 包名:lowercase(避免下划线)
mypackage/
# 常量:UPPERCASE_WITH_UNDERSCORES
MAX_RETRIES = 3
DATABASE_URL = "postgresql://..."
# 类名:PascalCase
class UserManager:
pass
class HTTPClient: # 缩写保持大写
pass
# 函数/方法:lowercase_with_underscores
def calculate_total(items: list[int]) -> int:
pass
# 私有成员:_leading_underscore
def _internal_helper():
pass
# 类型别名(Python 3.12+)
type UserId = int
type UserName = str
def calculate_average(numbers: list[float]) -> float:
"""计算数字列表的平均值.
使用标准算术平均值公式:sum(numbers) / len(numbers)
Args:
numbers: 浮点数列表,不能为空.
Returns:
列表中所有数字的平均值.
Raises:
ValueError: 如果列表为空.
Example:
>>> calculate_average([1.0, 2.0, 3.0])
2.0
"""
if not numbers:
raise ValueError("列表不能为空")
return sum(numbers) / len(numbers)
| AI 可能的理性化解释 | 实际应该检查的内容 |
|---|---|
| "这是临时代码,不需要遵循规范" | ✅ 是否所有代码都符合 PEP 8? |
| "变量名很明显,不需要类型注解" | ✅ 是否所有函数都有类型注解? |
| "这个函数很简单,不需要 docstring" | ✅ 是否所有公共函数都有 docstring? |
| "black 已经格式化过了" | ✅ 是否迁移到 ruff format? |
| "pip 安装很快" | ✅ 是否使用 uv 管理依赖? |
| "手动管理 import 顺序" | ✅ 是否使用 ruff 自动排序 import? |
[project]
name = "my-project"
version = "0.1.0"
requires-python = ">=3.13"
dependencies = [
"fastapi[standard]>=0.115.0",
"pydantic>=2.9.0",
]
[project.optional-dependencies]
dev = [
"pytest>=8.0.0",
"pytest-cov>=5.0.0",
"mypy>=1.11.0",
"ruff>=0.6.0",
]
[tool.ruff]
target-version = "py313"
line-length = 100
[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"UP", # pyupgrade
"ANN", # flake8-annotations(强制类型注解)
]
ignore = [
"E501", # line-too-long(交给 formatter 处理)
"ANN101", # missing-type-self
]
[tool.mypy]
python_version = "3.13"
strict = true
warn_return_any = true
disallow_untyped_defs = true
# 1. 格式化代码
ruff format .
# 2. Lint 检查并自动修复
ruff check --fix .
# 3. 类型检查
mypy src/
# 4. 运行测试
pytest --cov=src tests/
# 5. 安全检查
bandit -r src/
safety check
my-project/
├── src/
│ └── mypackage/
│ ├── __init__.py
│ ├── core.py
│ ├── models.py
│ └── utils.py
├── tests/
│ ├── conftest.py
│ ├── test_core.py
│ └── test_models.py
├── docs/
│ └── api.md
├── pyproject.toml
├── uv.lock # uv 锁文件
├── README.md
└── .gitignore