python-typing-and-async

Applies Python type hints and asyncio concurrency patterns with static checker enforcement.

Updated Dec 29, 2025
One-click install
npx skills add https://github.com/snoodleboot-io/discrecontinual_equations --skill python-typing-and-async-snoodleboot-io
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-typing-and-async
Source: https://github.com/snoodleboot-io/discrecontinual_equations/tree/main/.claude/skills/python-typing-and-async
Command: npx skills add https://github.com/snoodleboot-io/discrecontinual_equations --skill python-typing-and-async-snoodleboot-io

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Python type hints are never enforced by CPython at runtime, and asyncio code fails silently when blocking calls freeze the event loop or un-awaited tasks swallow errors. This Skill provides concrete patterns and anti-patterns so type annotations actually pass strict checkers and concurrent code behaves correctly. ## Core Features & Use Cases - Static Typing Patterns: Covers Protocol vs ABC, TypedDict for JSON payloads, Literal narrowing, generics with TypeVar and PEP 695 syntax, and strict mypy/pyright enforcement in CI. - Asyncio Concurrency Guidance: Explains the event loop, TaskGroup vs gather, offloading blocking work with asyncio.to_thread, and choosing between async, threads, and processes based on the GIL. - Anti-Pattern Detection: Flags common mistakes like using Any to silence checkers, blocking I/O inside coroutines, fire-and-forget tasks, and threads for CPU-bound work. - Use Case: When reviewing a FastAPI service, apply this Skill to annotate endpoint signatures with TypedDict response shapes, replace requests with httpx.AsyncClient in coroutines, and wrap background jobs in a TaskGroup so failures propagate. ## Quick Start Review my Python module for typing and asyncio issues, annotate the public functions, and fix any blocking calls inside coroutines.

Frequently Asked Questions about python-typing-and-async

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use Protocol vs ABC in Python typing?▼

Use a Protocol when a contract is satisfied by shape alone, since third-party classes conform automatically without inheritance. Use an abstract base class only when you also need to share implementation or force explicit registration.

How to run blocking code inside an asyncio coroutine?▼

Offload blocking calls with asyncio.to_thread, which runs the callable in a worker thread while the event loop stays responsive. For CPU-bound work, use a process pool instead because threads still contend on the GIL.

What is the difference between asyncio.gather and TaskGroup?▼

gather returns ordered results but leaves sibling tasks running if one raises an exception. TaskGroup cancels remaining tasks when any task fails and surfaces errors together, making it the safer default for structured concurrency.

Does Python enforce type hints at runtime?▼

No, CPython never checks type hints at runtime; they are verified only by external tools like mypy or pyright. Enable strict mode in CI so annotations stay in sync with the code instead of becoming misleading comments.

Why do threads not speed up CPU-bound Python code?▼

The Global Interpreter Lock serializes Python bytecode execution to one thread at a time, so ThreadPoolExecutor cannot parallelize computation. Use ProcessPoolExecutor or multiprocessing, where separate interpreters run truly in parallel.

When should I use TypedDict instead of a dataclass?▼

Use TypedDict to document and check the keys of a plain dict, which is ideal for JSON payloads at system boundaries without forcing a class or serialization step. NotRequired marks optional keys on Python 3.11 and later.