You need to review a small Python 3.12 module that builds an asynchronous summary of a task queue.
Environment and run: CPython 3.12.0, standard library only. The code runs as a regular module without additional frameworks. Verification is done with python -m unittest.
API contract:
QueueSummary(items) accepts an iterable of dictionaries with keys id and state.QueueSummary.collect() returns a list of strings of the form "<id>:<state>".build_report(items) asynchronously returns the same summary and uses a temporary file resource to buffer output.Functional requirements:
How to reproduce:
QueueSummary objects with different input lists and call collect() on both.build_report() on several items and compare the report strings.build_report() while it is waiting to verify resource closure.Assumptions: input elements are small dictionaries with two string fields; item order is preserved; input validation errors are not considered.
CPython 3.12.0; standard library only; execution mode: python -m unittest
Use line comments to explain the problem, its impact, the fix and how to test it.