8000 [3.11] gh-106498: Revert incorrect colorsys.rgb_to_hls change (GH-106627) by miss-islington · Pull Request #106633 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.11] gh-106498: Revert incorrect colorsys.rgb_to_hls change (GH-106627) #106633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
< 8000 copilot-diff-entry data-file-path="Lib/colorsys.py" >
2 changes: 1 addition & 1 deletion Lib/colorsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def rgb_to_hls(r, g, b):
if l <= 0.5:
s = rangec / sumc
else:
s = rangec / (2.0-sumc)
s = rangec / (2.0-maxc-minc) # Not always 2.0-sumc: gh-106498.
rc = (maxc-r) / rangec
gc = (maxc-g) / rangec
bc = (maxc-b) / rangec
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_colorsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ def test_hls_values(self):
self.assertTripleEqual(hls, colorsys.rgb_to_hls(*rgb))
self.assertTripleEqual(rgb, colorsys.hls_to_rgb(*hls))

def test_hls_nearwhite(self): # gh-106498
values = (
# rgb, hls: these do not work in reverse
((0.9999999999999999, 1, 1), (0.5, 1.0, 1.0)),
((1, 0.9999999999999999, 0.9999999999999999), (0.0, 1.0, 1.0)),
)
for rgb, hls in values:
self.assertTripleEqual(hls, colorsys.rgb_to_hls(*rgb))
self.assertTripleEqual((1.0, 1.0, 1.0), colorsys.hls_to_rgb(*hls))

def test_yiq_roundtrip(self):
for r in frange(0.0, 1.0, 0.2):
for g in frange(0.0, 1.0, 0.2):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Revert a change to :func:`colorsys.rgb_to_hls` that caused division by zero
for certain almost-white inputs. Patch by Terry Jan Reedy.
0