Skip to content

fix(color): allow whitespace around a color name, like the other formats - #442

Merged
yezz123 merged 1 commit into
pydantic:mainfrom
RavSinghChandan:color-name-whitespace
Oct 13, 2026
Merged

yezz123 merged 1 commit into
pydantic:mainfrom
RavSinghChandan:color-name-whitespace

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

Color(" 777 ") and Color(" rgba(0, 0, 128, 0.6) ") are accepted (both are in test_color_success), but a named color with surrounding whitespace, such as Color("red ") or Color(" transparent"), was rejected with "string not recognised as a valid color", because the name lookup used the string as is.

parse_str() now strips the value before the lookup, so names and transparent accept whitespace like every other format. original() still returns the input unchanged. Added cases to test_color_success.

@yezz123
yezz123 merged commit 9a96f7f into pydantic:main Oct 13, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants