Python

Structured concurrency & Go

How Python and Kotlin provide structured concurrency out of the box while Go achieves the same patterns explicitly using errgroup, WaitGroup, and context.

Hierarchical rate limiting with Redis sorted sets

Build multi-level rate limiting with Redis sorted sets and Lua. Enforce global and category-specific limits with ZREMRANGEBYSCORE and ZCARD commands.

Running only a single instance of a process

Prevent multiple script instances with file locking. Use flock in Bash, fcntl in Python, and syscall.Flock in Go for single-instance processes.

Injecting Pytest fixtures without cluttering test signatures

Clean up pytest test signatures using @pytest.mark.usefixtures to inject implicit fixtures without autouse or unused parameter warnings.

Explicit method overriding with @typing.override

Catch method override errors at type-check time with Python's @override decorator from PEP 698, preventing typos and signature mismatches.

Quicker startup with module-level __getattr__

Speed up Python module imports with __getattr__ from PEP 562 for lazy loading, deprecation warnings, and dynamic attribute access.

Shades of testing HTTP requests in Python

Test HTTP requests in Python with pytest-httpx for full mocking, respx for pattern matching, or VCR.py for recording real responses.

Taming parametrize with pytest.param

Write readable parametrized tests with pytest.param for better test names, conditional skips, custom IDs, and structured test data.

Log context propagation in Python ASGI apps

Automatically tag Python logs with request context using middleware and contextvars for distributed tracing in ASGI web applications.

Please don't hijack my Python root logger

Avoid configuring Python's root logger in libraries; use named loggers with NullHandler to let application code control logging behavior.

TypeIs does what I thought TypeGuard would do in Python

Understand TypeIs vs TypeGuard in Python: TypeIs provides more intuitive type narrowing by narrowing both positive and negative branches.

Patching pydantic settings in pytest

Mock pydantic_settings in pytest tests by patching the settings class to prevent flaky tests from environment variable dependencies.

Eschewing black box API calls

Why you should define API response structures explicitly. Compare approaches in Python, JavaScript, and Go with Pydantic, Zod, and structs.

Annotating args and kwargs in Python

Properly annotate Python *args and **kwargs with heterogeneous types using Unpack, TypedDict, and modern type hints from PEP-692.

Statically enforcing frozen data classes in Python

Enforce immutable dataclasses at type-check time with @final decorator to catch mutations before runtime without frozen=True performance cost.