A review needs to be performed for a small change in the reports module.
Context:
Functional requirements:
build_preview(items, limit=3) returns a list of the first limit elements of the input sequence in the original order.render_report(items, limit=3, formatter=str) returns a dictionary of the form {"count": int, "preview": list[str]}.count field must contain the total number of input elements.preview field must contain no more than the first limit elements after applying formatter to each of them.items can be either a collection (list, tuple) or a one-time iterator or generator.limit <= 0 is passed, the preview must be empty, and count must still reflect the total number of elements.formatter is called exactly for the elements that end up in the preview.What needs to be done:
Reproduction steps:
python -m app in the project directory.limit=0, for example from an interactive session:
render_report((n for n in [10, 20, 30, 40]), limit=2)render_report([1, 2, 3], limit=0)Assumptions:
CPython 3.12.0, standard library only. Project structure: files report.py and app.py in the same directory. Example run: python -m app.
Use line comments to explain the problem, its impact, the fix and how to test it.