Coverage for api/utils/help_text.py: 89%

7 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 06:14 +0000

1from collections.abc import Iterable 

2 

3 

4def make_comma_separated_help_text(items: Iterable[str], name: str) -> str: 

5 """ 

6 Generate help text containing a comma separated list of items with the given name. 

7 

8 Items are wrapped in backticks, and lists with more than one item will 

9 have an "and" added before the final item. 

10 

11 :param items: iterable of available options for this field 

12 :param name: plural name of the list of items (e.g. "categories", "aspect ratios") 

13 :return: generated help text 

14 """ 

15 

16 formatted = [f"`{item}`" for item in sorted(items)] 

17 # Add an "and" at the end of the list 

18 if len(formatted) > 1: 18 ↛ 20line 18 didn't jump to line 20 because the condition on line 18 was always true

19 formatted[-1] = f"and {formatted[-1]}" 

20 help_text = ( 

21 f"A comma separated list of {name}; available {name} include: " 

22 f"{', '.join(formatted)}." 

23 ) 

24 return help_text