/
/
/
# What does this implement/fix? `parse_value` in `helpers/api.py` had grown into one long function that handled every kind of annotation inline, and had tripped three of our complexity limits at once (two of them were silenced with a `noqa` in #5437 to keep that fix small). It is now a short dispatch that hands each kind of annotation to its own small helper, so both suppressions could go. While that helper was isolated, one rough edge in it was worth fixing too: a list, set or variadic tuple threw away the `None` entries it was given even when the annotation explicitly allowed them (`list[str | None]` came back as `['a']` instead of `['a', None]`), while a fixed-length tuple kept them since #5437. `None` entries are now kept when the element type allows them, and still dropped when it does not, so a plain `list[str]` keeps shrugging off nulls from a buggy client. Nothing in the API or the cache uses such an annotation today, so no behaviour anyone can reach changes. Beyond that the refactor is behaviour-preserving: `parse_value` is used for every incoming API argument and for rebuilding cached values, so the old and new versions were run side by side over 232 cases (every tuple spelling, lists/sets/frozensets/sequences/iterables, dicts, unions, enums, datetimes, models, and the value-conversion fallbacks) and matched on all of them, results and error messages alike, apart from the optional-element cases above. **Related issue (if applicable):** - follow-up on #5437 ## Types of changes - [ ] Bugfix (non-breaking change which fixes an issue) — `bugfix` - [ ] New feature (non-breaking change which adds functionality) — `new-feature` - [ ] Enhancement to an existing feature — `enhancement` - [ ] New music/player/metadata/plugin provider — `new-provider` - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) — `breaking-change` - [ ] Refactor (no behaviour change) — `refactor` - [ ] Documentation only — `documentation` - [x] Maintenance / chore — `maintenance` - [ ] CI / workflow change — `ci` - [ ] Dependencies bump — `dependencies` ## Changes - Split the fixed-length tuple, sequence, dict and union handling out of `parse_value` into one helper each. - Moved the value-conversion fallbacks (int/float/bool) into their own helper. - Dropped the `PLR0911` and `PLR0915` suppressions; the function now also fits within the branch limit that is globally ignored. - Keep the `None` entries of a list, set or variadic tuple when its element type allows them. - Added tests for the value conversion and union fallthrough paths, which had no coverage at all. ## Checklist - [x] The code change is tested and works locally. - [x] `pre-commit run --all-files` passes. - [x] `pytest` passes, and tests have been added/updated under `tests/` where applicable. - [ ] For changes to shared models, the companion PR in `music-assistant/models` is linked. - [ ] For changes affecting the UI, the companion PR in `music-assistant/frontend` is linked. - [x] I have read and complied with the project's [AI Policy](https://github.com/music-assistant/.github/blob/main/AI_POLICY.md) for any AI-assisted contributions. - [ ] I have [raised a PR against the documentation repository](https://github.com/music-assistant/music-assistant.io/blob/main/CONTRIBUTING.md) targeting the main or beta branch as appropriate.