Skip to content

Commit 6015059

Browse files
committed
Merge branch '3.12' of https://github.com/python/cpython into 3.12
2 parents 1336bb6 + c594e25 commit 6015059

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Lib/colorsys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def rgb_to_hls(r, g, b):
8383
if l <= 0.5:
8484
s = rangec / sumc
8585
else:
86-
s = rangec / (2.0-sumc)
86+
s = rangec / (2.0-maxc-minc) # Not always 2.0-sumc: gh-106498.
8787
rc = (maxc-r) / rangec
8888
gc = (maxc-g) / rangec
8989
bc = (maxc-b) / rangec

Lib/test/test_colorsys.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ def test_hls_values(self):
6969
self.assertTripleEqual(hls, colorsys.rgb_to_hls(*rgb))
7070
self.assertTripleEqual(rgb, colorsys.hls_to_rgb(*hls))
7171

72+
def test_hls_nearwhite(self): # gh-106498
73+
values = (
74+
# rgb, hls: these do not work in reverse
75+
((0.9999999999999999, 1, 1), (0.5, 1.0, 1.0)),
76+
((1, 0.9999999999999999, 0.9999999999999999), (0.0, 1.0, 1.0)),
77+
)
78+
for rgb, hls in values:
79+
self.assertTripleEqual(hls, colorsys.rgb_to_hls(*rgb))
80+
self.assertTripleEqual((1.0, 1.0, 1.0), colorsys.hls_to_rgb(*hls))
81+
7282
def test_yiq_roundtrip(self):
7383
for r in frange(0.0, 1.0, 0.2):
7484
for g in frange(0.0, 1.0, 0.2):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Revert a change to :func:`colorsys.rgb_to_hls` that caused division by zero
2+
for certain almost-white inputs. Patch by Terry Jan Reedy.

0 commit comments

Comments
 (0)