Fix division by zero bug in colorsys.rgb_to_hls() for near-white colors#139215
Closed
Anuj092 wants to merge 1 commit intopython:mainfrom
Anuj092:fix-colorsys-division-by-zero
Closed
Fix division by zero bug in colorsys.rgb_to_hls() for near-white colors#139215Anuj092 wants to merge 1 commit intopython:mainfrom Anuj092:fix-colorsys-division-by-zero
Anuj092 wants to merge 1 commit intopython:mainfrom
Anuj092:fix-colorsys-division-by-zero
Conversation
Fixes gh-106498: Prevent ZeroDivisionError when converting RGB values very close to white (e.g., (0.9999999999999999, 1, 1)) to HLS. Changes: - Add numerical stability check in rgb_to_hls() function - When denominator (2.0 - maxc - minc) is very close to zero, set s = 0.0 - Improve HSV hue handling with explicit normalization - Add test case for hue wrapping edge cases This fix prevents crashes when converting colors very close to pure white while maintaining backward compatibility and mathematical correctness.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Member
|
Hi @Anuj092! We appreciate your enthusiasm, but using AI to generate pull requests is not helpful. LLMs can be useful for many things, but in this case, it's just noise on our issue tracker (see our AI policy). The underlying bug that this PR is fixing has already been fixed since Python 3.10. If you're interested in contributing, you're free to use AI, but please be sure to use your own critical thinking before submitting a pull request. Thanks! |
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 gh-106498: Prevent ZeroDivisionError when converting RGB values very close to white (e.g., (0.9999999999999999, 1, 1)) to HLS.
Changes:
This fix prevents crashes when converting colors very close to pure white while maintaining backward compatibility and mathematical correctness.