Fix color parsing when TypeError - #312
Merged
Merged
Conversation
yezz123
approved these changes
Apr 18, 2025
yezz123
pushed a commit
that referenced
this pull request
Jul 18, 2026
…reject (#409) #312 widened `except ValueError` to `except (ValueError, TypeError)` in color.py to fix #311 ("Unhandled validation error when parsing Color"), because float() raises TypeError -- not ValueError -- for a value whose *type* it cannot take at all. Two call sites with the identical construct were not updated: Something(ulid=1.5) -> TypeError: object of type 'float' has no len() Color((0, 0, 0, [])) -> TypeError: float() argument must be a string... TypeError is not a subclass of ValueError, so neither except clause fires and the error escapes validate_python raw. - ulid.py:66 _validate_ulid is a wrap validator, so it sees the raw value before the inner union_schema can reject it; the else branch hands it to _ULID.from_bytes. - color.py:391 parse_float_alpha's own docstring says it raises PydanticCustomError "if the input value cannot be successfully parsed as a float"; a list cannot be. Same one-line widening as #312 in both, reusing each site's existing error. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #311