Idiomatic Python review
Review this Python code for correctness first, then typing, resource handling, exception boundaries, async behavior, and Python-specific maintainability. Distinguish runtime bugs from optional style improvements. Return a minimal patch and pytest cases for every behavioral change.