Catalogue / python
python
MITSignedModern Python: type hinting (Pydantic), async/asyncio, packaging. Trigger: "Python type hints", "async Python best practices", "FastAPI standards".--- name: python description: 'Modern Python: type hinting (Pydantic), async/asyncio, packaging. Trigger: "Python type hints", "async Python best practices", "FastAPI standards".' metadata: category: language-specific tags: "python, type-hints, pydantic, asyncio, packaging" ---
Modern Python Standards
Purpose
Ensures Python code is typed, async-safe, and packaged correctly. This skill may edit Python code and packaging metadata inside the requested scope; it does NOT write docstrings (see python-pydoc-engineer) or redesign application architecture.
When to Use / When NOT to Use
- Use: FastAPI services, data pipelines, modern CLI tools.
- NOT: Legacy Python 2 or untyped scripts.
- NOT: Docstring generation or audit (use
python-pydoc-engineer). - NOT: General smell removal or restructuring (use
code-quality-refactoring).
Prerequisites & Assumptions
- Python 3.11+.
Scope & Context Resolution
- Supported scopes: project/repository, package/module directory, file, class, function. Default: the files the user names; if none, the project's Python sources.
- Rule 1 - Explicit context in the prompt: The user's stated requirements, constraints, Python versions, tooling and scope are authoritative. Apply this skill strictly within them. MUST NOT add assumptions or expand beyond them. If a user instruction conflicts with a skill rule, follow the user and state the deviation in one line, EXCEPT security/data-loss rules, which stay mandatory: flag the conflict instead.
- Rule 2 - No extra context: Use this skill's Purpose, workflow and rules as the sole context, at the default scope. MUST NOT import unrelated requirements or assumptions.
- Rule 3 - Explicit scope: Operate ONLY inside the named scope. Out-of-scope files may be READ as evidence but MUST NOT be modified; report out-of-scope observations as notes, never as changes. Widening scope requires explicit user approval.
- Mutation boundary: Edits limited to typing, validation, async and packaging changes inside the resolved scope. MUST NOT change behavior, public signatures of out-of-scope code, or the dependency manager unless asked.
Step-by-Step Workflow
- Resolve scope and context: Apply Scope & Context Resolution; state the resolved scope and mutation boundary in one line at the start of the output.
- Use Pydantic V2 for data validation and serialization.
- Apply type hints strictly (
mypy/pyright). - Use
async/awaitfor I/O bound tasks. - Package with
Poetryoruv.
Apply steps 2-5 only to code inside the resolved scope.
Enterprise Rules & Standards (MUST / SHOULD / MUST NOT)
- MUST: Use type hints for all function signatures.
- MUST: Validate external inputs with Pydantic.
- MUST: Stay within the resolved scope; MUST NOT modify or expand beyond it without explicit user approval.
- SHOULD: Use
uvorPoetryfor dependency management. - MUST NOT: Use bare
except Exception: pass. - MUST NOT: Convert sync code to async, or migrate packaging tools, outside the requested scope.
Examples (good vs. bad, with realistic code or output)
- Bad:
def get_user(id): return db.query(id) - Good:
def get_user(id: int) -> User: ... - Good (scoped): Prompt "add type hints to
services/users.pyonly" -> annotate that module; note untyped functions inservices/orders.py. - Bad (scope-expanding): Same prompt -> annotate the whole package and switch the project from pip to
uv.
Checklist (verifiable, copy-pasteable)
- [ ] Scope and context resolved and stated.
- [ ] No changes outside the resolved scope.
- [ ] Type hints present and checked.
- [ ] Pydantic used for inputs.
- [ ] Exceptions specific.
Common Pitfalls
- Mutable default arguments (
def func(a=[])). - Blocking the async event loop with synchronous I/O.
- Scope creep: migrating packaging or converting unrelated modules to async.
References (official docs, standards)
| File | Size | SHA-256 |
|---|---|---|
| SKILL.md | 4.3 kB | 478a2d638e0f |
| SKILVAULT_SOURCE.json | 1.1 kB | 64335a5067ed |
| THIRD_PARTY_NOTICES.md | 1.1 kB | 48ef373d080c |
Published verbatim from the pinned commit. Nothing is rewritten.
| Version | Pinned commit | Signed | |
|---|---|---|---|
| 0.1.0 Current | 542909de2fb7 | 23 Nov 2026 |
Locking a skill to one version needs Pro.