8000 Update colorsys.py and test_colorsys.py to 3.12 (#5198) · RustPython/RustPython@92c8b37 · GitHub
[go: up one dir, main page]

Skip to content

Commit 92c8b37

Browse files
authored
Update colorsys.py and test_colorsys.py to 3.12 (#5198)
1 parent d8f2bd0 commit 92c8b37

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-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):

0 commit comments

Comments
 (0)
0