Python
Notes on the Python programming language — testing, async, type hints, and practical patterns.
Clean up pytest test signatures using @pytest.mark.usefixtures to inject implicit fixtures without autouse or unused parameter warnings.
Catch method override errors at type-check time with Python's @override decorator from PEP 698, preventing typos and signature mismatches.
Speed up Python module imports with __getattr__ from PEP 562 for lazy loading, deprecation warnings, and dynamic attribute access.
Test HTTP requests in Python with pytest-httpx for full mocking, respx for pattern matching, or VCR.py for recording real responses.
Write readable parametrized tests with pytest.param for better test names, conditional skips, custom IDs, and structured test data.
Automatically tag Python logs with request context using middleware and contextvars for distributed tracing in ASGI web applications.
Avoid configuring Python's root logger in libraries; use named loggers with NullHandler to let application code control logging behavior.
Understand TypeIs vs TypeGuard in Python: TypeIs provides more intuitive type narrowing by narrowing both positive and negative branches.
Mock pydantic_settings in pytest tests by patching the settings class to prevent flaky tests from environment variable dependencies.
Properly annotate Python *args and **kwargs with heterogeneous types using Unpack, TypedDict, and modern type hints from PEP-692.
Enforce immutable dataclasses at type-check time with @final decorator to catch mutations before runtime without frozen=True performance cost.
Set up VSCode debugger for containerized Python applications using debugpy. Step-by-step guide with Docker Compose and launch configurations.
Why you shouldn't add state-mutating methods to Python dataclasses. Maintain semantic clarity and use dataclasses as pure data containers.
Replace complex nested conditionals with Python's enum.Flag and bitmasks for cleaner, more maintainable logic using bitwise operations.
Prevent memory leaks in Python descriptors by using weakref to avoid hard references that prevent garbage collection of validated objects.