Skip to content

Commit 097314a

Browse files
committed
Minor fixes
1 parent 8332f55 commit 097314a

File tree

1 file changed

+7
-30
lines changed

1 file changed

+7
-30
lines changed

Diff for: tinycss2/color4.py

+7-30
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ def __init__(self, space, params, alpha=1):
2424
self.alpha = float(alpha)
2525

2626
def __repr__(self):
27-
return (
28-
f'color({self.space} '
29-
f'{" ".join(str(param) for param in self.params)} '
30-
f'/ {self.alpha})')
27+
params = ' '.join(str(param) for param in self.params)
28+
return f'color({self.space} {params} / {self.alpha})'
3129

3230
def __iter__(self):
3331
yield from self.params
@@ -84,7 +82,7 @@ def parse_color(input):
8482
int(group * multiplier, 16) / 255
8583
for group in match.groups()]
8684
if len(channels) == 3:
87-
channels.append(1.)
85+
channels.append(1)
8886
return srgb(*channels)
8987
elif token.type == 'function':
9088
tokens = [
@@ -121,21 +119,6 @@ def parse_color(input):
121119
return _parse_oklch(args, alpha)
122120

123121

124-
def _parse_separated_args(tokens):
125-
"""Parse a list of tokens given to a color function.
126-
127-
According to CSS Color Level 4, arguments must be made of a single token
128-
each, either comma seperated or space-seperated with an optional
129-
slash-seperated opacity.
130-
131-
Return a tuple containing:
132-
* the argument list without commas or white spaces, or None if the
133-
function token content do not match the description above; and
134-
* a boolean telling if a comma was found in the function parameters.
135-
136-
"""
137-
138-
139122
def _parse_alpha(args):
140123
"""Parse a list of one alpha value.
141124
@@ -175,7 +158,6 @@ def _parse_hsl(args, alpha):
175158
"""
176159
if (args[1].type, args[2].type) != ('percentage', 'percentage'):
177160
return
178-
179161
hue = _parse_hue(args[0])
180162
if hue is None:
181163
return
@@ -192,11 +174,9 @@ def _parse_hwb(args, alpha):
192174
"""
193175
if (args[1].type, args[2].type) != ('percentage', 'percentage'):
194176
return
195-
196177
hue = _parse_hue(args[0])
197178
if hue is None:
198179
return
199-
200180
white, black = (arg.value / 100 for arg in args[1:])
201181
if white + black >= 1:
202182
gray = white / (white + black)
@@ -278,9 +258,8 @@ def _parse_oklch(args, alpha):
278258
token, return xyz-d65 :class:`Color`. Otherwise, return None.
279259
280260
"""
281-
if len(args) != 3:
282-
return
283-
if {args[0].type, args[1].type} > {'number', 'percentage'}:
261+
if len(args) != 3 or (
262+
{args[0].type, args[1].type} > {'number', 'percentage'}):
284263
return
285264
L = args[0].value
286265
C = args[1].value * (1 if args[1].type == 'number' else 1.5)
@@ -296,11 +275,9 @@ def _oklab_to_xyz(L, a, b):
296275
# Code from https://www.w3.org/TR/css-color-4/#color-conversion-code
297276
lab = (L / 100, a, b)
298277
lms = [
299-
sum(_OKLAB_TO_LMS[i][j] * lab[j] for j in range(3))
300-
for i in range(3)]
278+
sum(_OKLAB_TO_LMS[i][j] * lab[j] for j in range(3)) for i in range(3)]
301279
X, Y, Z = [
302-
sum(_LMS_TO_XYZ[i][j] * lms[j] ** 3 for j in range(3))
303-
for i in range(3)]
280+
sum(_LMS_TO_XYZ[i][j] * lms[j]**3 for j in range(3)) for i in range(3)]
304281
return X, Y, Z
305282

306283

0 commit comments

Comments
 (0)