Raise ValueError instead of asserting ImageOps colorize() arguments#9825
Merged
radarhere merged 4 commits intoJul 27, 2026
Merged
Conversation
radarhere
reviewed
Jul 26, 2026
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
radarhere
reviewed
Jul 26, 2026
radarhere
approved these changes
Jul 26, 2026
radarhere
left a comment
Member
There was a problem hiding this comment.
My personal preference would be for error messages that are expressed in natural words, but I don't have any ideas for how to do so while still being succinct.
hugovk
reviewed
Jul 26, 2026
…sides Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
radarhere
reviewed
Jul 27, 2026
Contributor
Author
|
Thanks for the review and the wording PR — merged and much clearer than what I had. If there's anything else in ImageOps or the plugins you'd like a hand with, feel free to point me at it. |
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.
ImageOps.colorize()checks its arguments with bareassertstatements, which causes two problems.Invalid arguments raise an
AssertionErrorwith no message, so nothing tells you which argument was wrong:Under
python -Othe checks disappear entirely. Out-of-order points then reach the lookup table and fail with an internal message that says nothing about the arguments:A non-
Limage is the worst case: under-Othere is no error at all, and the function returns an image without applying the intended wedge.This raises
ValueErrorwith a message naming the argument at fault instead, the same way #9805 handled the assert in FtexImagePlugin.The range of accepted values is unchanged. I compared the new conditions against the old asserts over boundary and out-of-range combinations of blackpoint/midpoint/whitepoint, and they agree on all of them.
Changes proposed in this pull request:
ValueErrorinstead of asserting argument validity inImageOps.colorize()