8000 Avoid some uses of len-1 tuples. · matplotlib/matplotlib@66066ff · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 66066ff

Browse files
committed
Avoid some uses of len-1 tuples.
... when scalars or f-strings would do.
1 parent 803fd69 commit 66066ff

File tree

4 files changed

+12
-22
lines changed

4 files changed

+12
-22
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,14 +684,11 @@ def draw_gouraud_triangles(self, gc, points, colors, trans):
684684
xmax, ymax = points_max
685685

686686
streamarr = np.empty(
687-
(shape[0] * shape[1],),
688-
dtype=[('flags', 'u1'),
689-
('points', '>u4', (2,)),
690-
('colors', 'u1', (3,))])
687+
shape[0] * shape[1],
688+
dtype=[('flags', 'u1'), ('points', '2>u4'), ('colors', '3u1')])
691689
streamarr['flags'] = 0
692690
streamarr['points'] = (flat_points - points_min) * factor
693691
streamarr['colors'] = flat_colors[:, :3] * 255.0
694-
695692
stream = quote_ps_string(streamarr.tostring())
696693

697694
self._pswriter.write(f"""\

lib/matplotlib/offsetbox.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,14 @@ def _get_packed_offsets(wd_list, total, sep, mode="fixed"):
9191
offsets : array of float
9292
The left offsets of the boxes.
9393
"""
94-
w_list, d_list = zip(*wd_list)
95-
# d_list is currently not used.
94+
w_list, d_list = zip(*wd_list) # d_list is currently not used.
95+
cbook._check_in_list(["fixed", "expand", "equal"], mode=mode)
9696

9797
if mode == "fixed":
9898
offsets_ = np.cumsum([0] + [w + sep for w in w_list])
9999
offsets = offsets_[:-1]
100100
if total is None:
101101
total = offsets_[-1] - sep
102-
return total, offsets
103102

104103
elif mode == "expand":
105104
# This is a bit of a hack to avoid a TypeError when *total*
@@ -112,22 +111,19 @@ def _get_packed_offsets(wd_list, total, sep, mode="fixed"):
112111
sep = 0
113112
offsets_ = np.cumsum([0] + [w + sep for w in w_list])
114113
offsets = offsets_[:-1]
115-
return total, offsets
116114

117115
elif mode == "equal":
118116
maxh = max(w_list)
119117
if total is None:
120118
if sep is None:
121119
raise ValueError("total and sep cannot both be None when "
122-
"using layout mode 'equal'.")
120+
"using layout mode 'equal'")
123121
total = (maxh + sep) * len(w_list)
124122
else:
125123
sep = total / len(w_list) - maxh
126124
offsets = (maxh + sep) * np.arange(len(w_list))
127-
return total, offsets
128125

129-
else:
130-
raise ValueError("Unknown mode : %s" % (mode,))
126+
return total, offsets
131127

132128

133129
def _get_aligned_offsets(hd_list, height, align="baseline"):
@@ -146,6 +142,8 @@ def _get_aligned_offsets(hd_list, height, align="baseline"):
146142

147143
if height is None:
148144
height = max(h for h, d in hd_list)
145+
cbook._check_in_list(
146+
["baseline", "left", "top", "right", "bottom", "center"], align=align)
149147

150148
if align == "baseline":
151149
height_descent = max(h - d for h, d in hd_list)
@@ -161,8 +159,6 @@ def _get_aligned_offsets(hd_list, height, align="baseline"):
161159
elif align == "center":
162160
descent = 0.
163161
offsets = [(height - h) * .5 + d for h, d in hd_list]
164-
else:
165-
raise ValueError("Unknown Align mode : %s" % (align,))
166162

167163
return height, descent, offsets
168164

lib/matplotlib/patches.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3864,14 +3864,11 @@ class FancyArrowPatch(Patch):
38643864
_edge_default = True
38653865

38663866
def __str__(self):
3867-
38683867
if self._posA_posB is not None:
38693868
(x1, y1), (x2, y2) = self._posA_posB
3870-
return self.__class__.__name__ \
3871-
+ "((%g, %g)->(%g, %g))" % (x1, y1, x2, y2)
3869+
return f"{type(self).__name__}(({x1:g}, {y1:g})->({x2:g}, {y2:g}))"
38723870
else:
3873-
return self.__class__.__name__ \
3874-
+ "(%s)" % (str(self._path_original),)
3871+
return f"{type(self).__name__}({self._path_original})"
38753872

38763873
@docstring.dedent_interpd
38773874
def __init__(self, posA=None, posB=None,

lib/matplotlib/path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,8 @@ def unit_regular_star(cls, numVertices, innerCircle=0.5):
688688
theta += np.pi / 2.0
689689
r = np.ones(ns2 + 1)
690690
r[1::2] = innerCircle
691-
verts = np.vstack((r*np.cos(theta), r*np.sin(theta))).transpose()
692-
codes = np.empty((ns2 + 1,))
691+
verts = (r * np.vstack((np.cos(theta), np.sin(theta)))).T
692+
codes = np.empty(ns2 + 1)
693693
codes[0] = cls.MOVETO
694694
codes[1:-1] = cls.LINETO
695695
codes[-1] = cls.CLOSEPOLY

0 commit comments

Comments
 (0)
0