AgentSkillsCN

arch-python-modern

遵循现代Python 3.10+开发标准,包括类型提示、异步编程模式、pathlib库、数据类,以及推荐的工具链(uv、Ruff、pytest)。适用于Python代码评审、新功能的实现、遗留代码的重构,或为Python项目制定架构决策。

SKILL.md
--- frontmatter
name: arch-python-modern
description: Modern Python 3.10+ development standards including type hints, async patterns, pathlib, dataclasses, and recommended tooling (uv, Ruff, pytest). Use for Python code review, new feature implementation, refactoring legacy code, or making architecture decisions about Python projects.
allowed-tools: Read, Grep, Glob

Modern Python Standards

Development practices for Python 3.10+ focusing on type safety, modern idioms, and efficient tooling.

Core Defaults

python
# Always use modern patterns
from pathlib import Path
from typing import Any
from dataclasses import dataclass

def process(items: list[dict[str, Any]]) -> dict[str, int] | None:
    config_path = Path("config.json")
    return {"count": len(items)} if items else None

Recommended Stack

CategoryTool
Package Managementuv (preferred) or Poetry
Linting/FormattingRuff
Type Checkingmypy (strict mode)
Testingpytest with coverage
Web APIsFastAPI
Data ProcessingPolars or Pandas

Key Patterns

Type Hints

  • All public functions must have type hints
  • Use X | None for nullable values (3.10+)
  • Prefer list[X] over List[X] (3.9+)
  • Use TypeVar for generic functions

Async

  • Use asyncio with modern patterns
  • Avoid blocking in async contexts
  • asyncio.gather() for concurrent operations
  • asyncio.TaskGroup for structured concurrency (3.11+)

Path Handling

  • Always pathlib.Path over os.path
  • Use .read_text(), .write_text()
  • Proper path resolution, no hardcoding

Error Handling

  • Specific exceptions, never bare except:
  • Context managers for resources
  • Proper logging with structlog

Anti-Patterns to Avoid

BadGood
os.path.join()Path() / "file"
% formattingf-strings
pip installuv add
flake8Ruff
List[str]list[str]
Optional[X]X | None
Mutable default argsfield(default_factory=list)

See reference.md for detailed patterns and examples.md for code samples.