mcpField
P
python-coder

python-coder

github.com/majesticlabs-dev开发5052 次安装7 周前更新
代码仓库

关于 python-coder

python-coder 面向使用 Python 3.12 及更高版本的开发者,提供现代工具、语言模式、类型标注和代码质量实践指南。

主要功能

  1. 01uv 包管理示例
  2. 02ruff 格式化与 lint 指南
  3. 03pyright 和 mypy 类型检查配置
  4. 04模式匹配与异步代码示例
  5. 05测试和错误处理规范

适用场景

  1. 01使用 uv 启动 Python 3.12 项目
  2. 02配置 lint 和类型检查
  3. 03编写异步 Python 代码
  4. 04采用类型标注和测试规范

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/majesticlabs-dev/majestic-marketplace --skill python-coder

安装后在 Claude Code 中输入/python-coder确认已加载。

详细介绍

Python-Coder

现代 Python 3.12+ 开发模式。

相关技能(按需使用)

技能使用场景
fastapi-coder构建 FastAPI 服务
django-coderDjango Web 应用
pytest-coder编写全面的测试
python-debugger调试 Python 代码

现代工具速查

包管理(uv)
# Project setup
uv init my-project
uv add fastapi pydantic
uv add --dev pytest ruff mypy

# Run commands
uv run python main.py
uv run pytest
代码质量(ruff)
# pyproject.toml
[tool.ruff]
line-length = 100
target-version = "py312"

[tool.ruff.lint]
select = ["E", "F", "I", "UP", "B"]

[tool.ruff.format]
quote-style = "double"
类型检查(pyright/mypy)
[tool.pyright]
pythonVersion = "3.12"
typeCheckingMode = "strict"

Python 3.12+ 模式

模式匹配
match command:
    case {"action": "create", "item": item}:
        create(item)
    case {"action": "delete", "id": int(id)}:
        delete(id)
    case _:
        raise ValueError("Unknown command")
现代异步编程
async def fetch_all(urls: list[str]) -> list[dict]:
    async with aiohttp.ClientSession() as session:
        tasks = [fetch(session, url) for url in urls]
        return await asyncio.gather(*tasks)
类型提示
from typing import TypeVar, Protocol

T = TypeVar("T")

class Repository(Protocol[T]):
    def get(self, id: int) -> T | None: ...
    def save(self, entity: T) -> T: ...

行为规范

  • 遵循 PEP 8 并使用 ruff 格式化
  • 全面使用类型提示
  • 使用 pytest 编写测试(覆盖率目标 >90%)
  • 优先使用标准库,再考虑外部依赖
  • 通过自定义异常进行全面的错误处理

评论

支持 Markdown