Skip to content

Fix none hue output when the angle unit is not degrees - #531

Merged
facelessuser merged 2 commits into
facelessuser:mainfrom
spicysharkco:fix/none-angle-unit
Oct 20, 2026
Merged

facelessuser merged 2 commits into
facelessuser:mainfrom
spicysharkco:fix/none-angle-unit

Conversation

@spicysharkco

Copy link
Copy Markdown
Contributor

to_string() appends the angle unit to an undefined hue:

Color('hsl(none 50% 50%)').to_string(none=True, angle='turn')
# 'hsl(noneturn 50 50)'

noneturn is not valid CSS, and Color() cannot read it back. The strings docs say undefined channels "can be displayed as none" on output, so the result should be hsl(none 50 50). rad and grad do the same, and so does color=True. deg has no suffix, so it was already correct.

angle was added in 6.1. I ran the example on every tag from 6.1 to 8.13.1 and all of them give the wrong result.

color_function adds the unit whether or not the value is NaN (serialize.py#L105). Color.__repr__ already leaves the unit off for NaN, and the fix does the same.

Test: pytest tests/test_api.py -k test_to_string_angle fails on main with 'hsl(nonerad 50 50)' != 'hsl(none 50 50)' and passes with the change.

An undefined hue was written with the `angle` unit appended, such as
`hsl(noneturn 50 50)`. That is not valid CSS and cannot be parsed back.
@gir-bot gir-bot added S: needs-review Needs to be reviewed and/or approved. C: source Related to source code. C: tests Related to testing. labels Oct 20, 2026
@facelessuser

Copy link
Copy Markdown
Owner

Please add a note in the change log.

@spicysharkco

Copy link
Copy Markdown
Contributor Author

Added a changelog entry under 8.13.2.

@gir-bot gir-bot added the C: docs Related to documentation. label Oct 20, 2026
@facelessuser

Copy link
Copy Markdown
Owner

@gir-bot lgtm

@gir-bot gir-bot added S: approved The pull request is ready to be merged. and removed S: needs-review Needs to be reviewed and/or approved. labels Oct 20, 2026
@facelessuser
facelessuser merged commit 4888fc2 into facelessuser:main Oct 20, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C: docs Related to documentation. C: source Related to source code. C: tests Related to testing. S: approved The pull request is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants