python-core-idioms
2
总安装量
2
周安装量
#68393
全站排名
安装命令
npx skills add https://github.com/sraloff/gravityboots --skill python-core-idioms
Agent 安装分布
opencode
2
gemini-cli
2
claude-code
2
github-copilot
2
codex
2
kimi-cli
2
Skill 文档
Python Core Idioms (3.12+)
When to use this skill
- Writing new Python code.
- Refactoring legacy Python scripts.
- Configuring linters (Ruff, MyPy).
1. Modern Syntax (3.10 – 3.12+)
- Type Hinting: Mandatory for function signatures. Use
list[str],dict[str, int](builtin generics) instead ofList,Dictfromtyping. - Union Types: Use
str | Noneinstead ofOptional[str]. - Pattern Matching: Use
match / casefor complex control flow (structural pattern matching). - Walrus Operator: Use
:=for assignment expression inif/whileconditions when it improves readability (e.g., regex matching). - f-strings: Use for all string interpolation.
2. Data Structures
- Dataclasses: Use
@dataclassfor data holding classes instead of strict dictionaries or raw classes.frozen=Truefor immutability.
- TypedDict: For legacy JSON schemas where classes don’t fit.
- Enum: Inherit from
StrEnum(3.11+) if string behavior is needed.
3. Project Structure
- pyproject.toml: Standard for configuration (ruff, pytest, mypy).
- Virtual Envs: Always use a venv or uv/poetry environment.