Reference library

Modern tooling

uv, ruff, pyproject.toml, packaging, and current Python project workflows.

2 matches
Modern tooling easy

How to Type Check a Mock with pyright in Python

Shows how pyright validates a mock function against a TypedDict and Callable signature before runtime.

pyright type-checking mocking
Python
from typing import TypedDict, Callable


class User(TypedDict):
    id: int
    name: str


def get_user_name(user_id: int, get_user: Callable[[int], User]) -> str:
    user = get_user(user_id)
    return user["name"]


def mock_get_user(user_id: int) -> User:
    return {"id": user_id, "name": f"User {user_id}"}


if…
15 0 Open
Modern tooling easy

How to Validate Data with a Simple Dict-Based Rules Helper in Python

Validates a dictionary against a set of callable rules, printing pass/fail per field and returning an overall boolean.

validation dictionary helper
Python
import json
from pathlib import Path
from typing import Any, Callable


def validate_data(
    data: dict[str, Any],
    rules: dict[str, Callable[[Any], bool]],
    path: Path | None = None,
) -> bool:
    """Validate a dict against a set of simple rules."""
    all_valid = True
    for field, validator in rules.item…
15 0 Open

Browse by section

Each section groups closely related Python snippets.

Modern tooling — Python code examples

What you will find here

This page collects modern tooling snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.