Split Python style skill into focused modules
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
---
|
||||
name: python-anyio-async
|
||||
description: Use when working on Python async code in repositories that already use or are explicitly standardizing on anyio. Apply task-group, cancellation, timeout, and async-boundary patterns without migrating established asyncio, trio, or synchronous code unless requested.
|
||||
---
|
||||
|
||||
# Python AnyIO Async
|
||||
|
||||
Use this skill for `anyio`-based async implementation work. It is not a general license to rewrite a repository's async model.
|
||||
|
||||
## Priority Order
|
||||
|
||||
1. Explicit user instructions
|
||||
2. Existing repository async conventions and verification workflow
|
||||
3. This skill
|
||||
|
||||
Only apply this skill when the repository already uses `anyio` or the user explicitly asks to standardize on it.
|
||||
|
||||
## Before Applying This Skill
|
||||
|
||||
Check the local project first:
|
||||
|
||||
- existing async imports and helpers
|
||||
- current task runner and verification commands
|
||||
- whether the code is `anyio`, `asyncio`, `trio`, or sync-only
|
||||
- whether the CLI entrypoint is already established
|
||||
|
||||
If the repository is built around `asyncio`, `trio`, or synchronous code, keep that model unless the user asks for a migration.
|
||||
|
||||
## Defaults
|
||||
|
||||
- Prefer `anyio.create_task_group()` over manual task orchestration.
|
||||
- Prefer `anyio.fail_after()` or cancellation scopes for time-bounded work.
|
||||
- Use `anyio` streams and synchronization primitives instead of mixing in raw `asyncio` APIs.
|
||||
- For async CLIs that already use `anyio`, keep a synchronous entrypoint that calls `anyio.run(...)`.
|
||||
- When an `asyncio` boundary is unavoidable, isolate it and leave a short note.
|
||||
|
||||
```python
|
||||
from pathlib import Path
|
||||
|
||||
import anyio
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument("config_path", type=click.Path(path_type=Path))
|
||||
def main(config_path: Path) -> None:
|
||||
anyio.run(run, config_path)
|
||||
|
||||
|
||||
async def run(config_path: Path) -> None:
|
||||
async with await anyio.open_file(config_path) as fh:
|
||||
_ = await fh.read()
|
||||
```
|
||||
|
||||
## Verification
|
||||
|
||||
Use the repository's existing verification workflow first.
|
||||
|
||||
If no local workflow exists and the repository is already aligned with this stack:
|
||||
|
||||
1. run the configured type checker
|
||||
2. run the async test suite or `pytest`
|
||||
3. run a CLI or module smoke test that exercises the async boundary when relevant
|
||||
|
||||
## Anti-Goals
|
||||
|
||||
- Do not replace an established `asyncio` or `trio` codebase with `anyio` unless asked.
|
||||
- Do not mix manual event-loop management into `anyio` code without a forced integration boundary.
|
||||
- Do not use this skill for synchronous code just because it contains a small async helper.
|
||||
Reference in New Issue
Block a user