Skip to content

Commit 4fe3767

Browse files
committed
Speed up pretty printing
1 parent 3314fa9 commit 4fe3767

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

coloraide/algebra.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,10 +1308,11 @@ def pretty(value: Number | ArrayTLike[Number], *, _depth: int = 0, shape: Shape
13081308
if shape is None:
13091309
shape = _shape(value)
13101310

1311-
nl = len(shape) - _depth - 1
1312-
if isinstance(value, Sequence):
1313-
seq = len(value) and isinstance(value[0], Sequence)
1314-
values = [pretty(v, _depth=_depth + 1, shape=shape) for v in value]
1311+
nl = len(shape) - 1
1312+
if shape:
1313+
seq = len(shape) > 1 and shape[0]
1314+
sub_seq = shape[1:]
1315+
values = [pretty(v, _depth=_depth + 1, shape=sub_seq) for v in cast('ArrayTLike[Number]', value)]
13151316
spacing = _depth + 1
13161317
return '[{}]'.format((',{}{}'.format('\n' * nl, ' ' * spacing) if seq else ', ').join(values))
13171318

0 commit comments

Comments
 (0)