From 5209a13084536975907cf48aed0cd4401c25d974 Mon Sep 17 00:00:00 2001 From: aiwonderland <94027126+aiwonderland@users.noreply.github.com> Date: Fri, 10 Apr 2026 13:26:04 +0000 Subject: [PATCH 1/2] gh-148330: colorsys: Add docstrings to module and all functions --- Lib/colorsys.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Lib/colorsys.py b/Lib/colorsys.py index e97f91718a3a30..388844cb6d29ad 100644 --- a/Lib/colorsys.py +++ b/Lib/colorsys.py @@ -38,12 +38,21 @@ # The ones in this library uses constants from the FCC version of NTSC. def rgb_to_yiq(r, g, b): + """Convert RGB to YIQ. + + r, g, b are in [0, 1]. + Return (y, i, q) where y is in [0, 1]. + """ y = 0.30*r + 0.59*g + 0.11*b i = 0.74*(r-y) - 0.27*(b-y) q = 0.48*(r-y) + 0.41*(b-y) return (y, i, q) def yiq_to_rgb(y, i, q): + """Convert YIQ to RGB. + + Return (r, g, b) in [0, 1]. + """ # r = y + (0.27*q + 0.41*i) / (0.74*0.41 + 0.27*0.48) # b = y + (0.74*q - 0.48*i) / (0.74*0.41 + 0.27*0.48) # g = y - (0.30*(r-y) + 0.11*(b-y)) / 0.59 @@ -73,6 +82,11 @@ def yiq_to_rgb(y, i, q): # S: color saturation def rgb_to_hls(r, g, b): + """Convert RGB to HLS (Hue, Lightness, Saturation). + + r, g, b are in [0, 1]. + Return (h, l, s) in [0, 1]. + """ maxc = max(r, g, b) minc = min(r, g, b) sumc = (maxc+minc) @@ -97,6 +111,11 @@ def rgb_to_hls(r, g, b): return h, l, s def hls_to_rgb(h, l, s): + """Convert HLS (Hue, Lightness, Saturation) to RGB. + + h, l, s are in [0, 1]. + Return (r, g, b) in [0, 1]. + """ if s == 0.0: return l, l, l if l <= 0.5: @@ -123,6 +142,11 @@ def _v(m1, m2, hue): # V: color brightness def rgb_to_hsv(r, g, b): + """Convert RGB to HSV (Hue, Saturation, Value). + + r, g, b are in [0, 1]. + Return (h, s, v) in [0, 1]. + """ maxc = max(r, g, b) minc = min(r, g, b) rangec = (maxc-minc) @@ -143,6 +167,11 @@ def rgb_to_hsv(r, g, b): return h, s, v def hsv_to_rgb(h, s, v): + """Convert HSV (Hue, Saturation, Value) to RGB. + + h, s, v are in [0, 1]. + Return (r, g, b) in [0, 1]. + """ if s == 0.0: return v, v, v i = int(h*6.0) # XXX assume int() truncates! From 2a96f04cd82a553f298f9d37cf08de5484f65b67 Mon Sep 17 00:00:00 2001 From: aiwonderland <94027126+aiwonderland@users.noreply.github.com> Date: Sat, 11 Apr 2026 11:48:03 +0800 Subject: [PATCH 2/2] Update Lib/colorsys.py with let docstring more neater Co-authored-by: Rihaan Meher --- Lib/colorsys.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/colorsys.py b/Lib/colorsys.py index 388844cb6d29ad..5489fd32a7d7c2 100644 --- a/Lib/colorsys.py +++ b/Lib/colorsys.py @@ -38,7 +38,8 @@ # The ones in this library uses constants from the FCC version of NTSC. def rgb_to_yiq(r, g, b): - """Convert RGB to YIQ. + """ + Convert RGB to YIQ. r, g, b are in [0, 1]. Return (y, i, q) where y is in [0, 1].