Borrowing it
Nothing to install: this file belongs to MisonL/Ling. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.
curl -O https://raw.githubusercontent.com/MisonL/Ling/main/.agents/skills/python-patterns/SKILL.mdgit clone --depth 1 https://github.com/MisonL/LingWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/misonl/ling/python-patterns)<a href="https://agentmods.dev/skills/misonl/ling/python-patterns"><img src="https://agentmods.dev/badge/skills/misonl/ling/python-patterns/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/misonl/ling/python-patterns"><img src="https://agentmods.dev/badge/skills/misonl/ling/python-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00043 | $0.02860 |
| Opus 5.5 | $0.00017 | $0.01144 |
| Sonnet 5.5 | $0.00009 | $0.00572 |
| Haiku 4.5 | $0.00004 | $0.00286 |
Grade A, and why
python-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 442 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Python 模式
面向 2025 的 Python 开发原则与决策方法。
学习如何思考,不要只记模式。
[WARN] 本技能使用方式
本技能强调决策原则,不是固定代码模板。
- 需求不明确时,先询问用户框架偏好
- 根据 Context(上下文)决定 async(异步)或 sync(同步)
- 不要每次都默认同一框架
1. 框架选型(2025)
决策树
你要构建什么?
|
+-- API 优先(API-first)/ 微服务
| +-- FastAPI(async、现代、速度快)
|
+-- 全栈 Web / CMS / 管理后台
| +-- Django(开箱即用,batteries-included)
|
+-- 简单应用 / 脚本 / 学习
| +-- Flask(极简、灵活)
|
+-- AI/ML API 服务化
| +-- FastAPI(Pydantic、async、Uvicorn)
|
+-- 后台任务
+-- Celery + 任意 Web 框架
对比原则
| 维度 | FastAPI | Django | Flask |
|---|---|---|---|
| 适用场景 | API、微服务 | 全栈、CMS | 简单项目、学习 |
| 异步支持 | 原生支持 | Django 5.0+ | 依赖扩展 |
| 管理后台 | 手动构建 | 内置 Admin(管理后台) | 依赖扩展 |
| ORM(对象关系映射) | 自由选择 | Django ORM | 自由选择 |
| 学习曲线 | 低 | 中 | 低 |
选型前必须询问:
- 是纯 API 还是全栈应用?
- 是否需要后台管理界面?
- 团队是否熟悉 async?
- 是否有现有基础设施约束?
2. 异步与同步决策
何时使用异步(async)
async def(异步函数)更适合:
+-- I/O 密集操作(数据库、HTTP、文件)
+-- 大量并发连接
+-- 实时交互场景
+-- 微服务通信
+-- FastAPI/Starlette/Django ASGI(异步服务器网关接口)
def(同步函数)更适合:
+-- CPU 密集操作
+-- 简单脚本
+-- 遗留代码库
+-- 团队不熟悉 async
+-- 依赖阻塞型库(无 async 版本)
黄金法则
I/O bound(I/O 密集)-> async(等待外部资源)
CPU bound(CPU 密集)-> sync + multiprocessing(本地计算)
不要:
+-- 随意混用 sync 与 async
+-- 在 async 代码里调用阻塞库
+-- 为 CPU 任务强行上 async
异步库选型
| 需求 | 异步库 |
|---|---|
| HTTP 客户端 | httpx |
| PostgreSQL | asyncpg |
| Redis(内存数据库) | aioredis / redis-py async |
| 文件 I/O | aiofiles |
| 数据库 ORM | SQLAlchemy 2.0 async, Tortoise |
3. 类型标注策略
哪些地方要标注
必须标注:
+-- 函数参数
+-- 返回类型
+-- 类属性
+-- 对外公开 API
可省略:
+-- 局部变量(让推断工作)
+-- 一次性脚本
+-- 测试代码(通常可选)
常见类型模式
# 下面是模式示例,请理解其语义:
# Optional(可选)-> 可能为 None
from typing import Optional
def find_user(id: int) -> Optional[User]: ...
# Union(联合类型)-> 多类型之一
def process(data: str | dict) -> None: ...
# 泛型集合
def get_items() -> list[Item]: ...
def get_mapping() -> dict[str, int]: ...
# Callable(可调用)
from typing import Callable
def apply(fn: Callable[[int], str]) -> str: ...
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 1mo ago First seen · 442 lines · 43 tokens per session scan A 8de8dd5e7263
python-patterns is a skill published in the GitHub repository MisonL/Ling (8 stars, last pushed 7mo ago), licensed MIT. It adds 43 tokens to every session and 2,860 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other skills, from other repositories
matlab
Builds, reviews, migrates, and plans MATLAB or GNU Octave numerical workflows. Use for arrays, tabular/time data, tests, projects, graphics, MAT files, and explicit Python interoperability.
pennylane
Builds and differentiates PennyLane quantum circuits, hybrid PyTorch or JAX models, molecular VQE and QAOA workflows. Use for variational quantum algorithms, quantum machine learning, simulator validation, and moving validated circuits to provider plugins. For hardware-specific compilation use qiskit or cirq; for…
holoscan-install-wheel
Install Holoscan SDK 5.x CUDA 13 Python wheels in an isolated environment, choosing the full stack or version-matched components.
rocm-kernels
Provides guidance for writing and benchmarking optimized Triton kernels for AMD GPUs (MI355X, R9700) on ROCm, targeting HuggingFace diffusers (LTX-Video, SD3, FLUX) and transformers. Core kernels: RMSNorm, RoPE 3D, GEGLU, AdaLN. Includes XCD swizzle, autotune, diffusers integration patterns, and LTX-Video pipeline…
typing-exclusion-worker
Python typing exclusion worker: remove assigned mypy exclusion modules in small scoped batches, fix typing issues, run validation, and produce a structured completion summary. Use when running parallel typing-debt workers or when asked to remove modules from pyproject mypy exclusion overrides.
python
Python development with ruff, mypy, pytest - TDD and type safety.