diff options
author | Thomas Wouters <thomas@python.org> | 2023-07-11 16:05:57 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2023-07-11 16:05:57 (GMT) |
commit | 60150590c74ff397ed07ef7bd752ad2f1d5cfde5 (patch) | |
tree | 62015dee833e18236189714bfc692630923ef764 /Lib | |
parent | 1336bb667b4eb112afdc7d7f94a9022cfe64d3ec (diff) | |
parent | c594e25cd76b9d2be04eaebc13df2becbdda7aed (diff) | |
download | cpython-60150590c74ff397ed07ef7bd752ad2f1d5cfde5.zip cpython-60150590c74ff397ed07ef7bd752ad2f1d5cfde5.tar.gz cpython-60150590c74ff397ed07ef7bd752ad2f1d5cfde5.tar.bz2 |
Merge branch '3.12' of https://github.com/python/cpython into 3.12
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/colorsys.py | 2 | ||||
-rw-r--r-- | Lib/test/test_colorsys.py | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/Lib/colorsys.py b/Lib/colorsys.py index 9bdc83e..bc897bd 100644 --- a/Lib/colorsys.py +++ b/Lib/colorsys.py @@ -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 diff --git a/Lib/test/test_colorsys.py b/Lib/test/test_colorsys.py index a24e3ad..74d7629 100644 --- a/Lib/test/test_colorsys.py +++ b/Lib/test/test_colorsys.py @@ -69,6 +69,16 @@ class ColorsysTest(unittest.TestCase): 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): |