Skip to content

Commit eb1e4bc

Browse files
committed
Cleanup list copying
1 parent 5d660a4 commit eb1e4bc

File tree

6 files changed

+27
-13
lines changed

6 files changed

+27
-13
lines changed

doc/sphinxext/missing_references.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def prepare_missing_references_handler(app):
254254

255255
sphinx_logger = logging.getLogger('sphinx')
256256
missing_reference_filter = MissingReferenceFilter(app)
257-
for handler in sphinx_logger.handlers[:]:
257+
for handler in sphinx_logger.handlers:
258258
if (isinstance(handler, sphinx_logging.WarningStreamHandler)
259259
and missing_reference_filter not in handler.filters):
260260

lib/matplotlib/artist.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1065,8 +1065,8 @@ def update_from(self, other):
10651065
self._label = other._label
10661066
self._sketch = other._sketch
10671067
self._path_effects = other._path_effects
1068-
self.sticky_edges.x[:] = other.sticky_edges.x[:]
1069-
self.sticky_edges.y[:] = other.sticky_edges.y[:]
1068+
self.sticky_edges.x[:] = other.sticky_edges.x.copy()
1069+
self.sticky_edges.y[:] = other.sticky_edges.y.copy()
10701070
self.pchanged()
10711071
self.stale = True
10721072

lib/matplotlib/backend_bases.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ def __init__(self, interval=None, callbacks=None):
10591059
if callbacks is None:
10601060
self.callbacks = []
10611061
else:
1062-
self.callbacks = callbacks[:] # Create a copy
1062+
self.callbacks = callbacks.copy()
10631063

10641064
if interval is None:
10651065
self._interval = 1000

lib/matplotlib/backends/backend_svg.py

+21-7
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,19 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
650650
self._path_collection_id += 1
651651

652652
def draw_gouraud_triangle(self, gc, points, colors, trans):
653+
"""
654+
Write the code for a gouraud-shaded triangle to ``self.writer``.
655+
656+
Parameters
657+
----------
658+
gc : `.GraphicsContextBase`
659+
The graphics context.
660+
points : (3, 2) array
661+
The x and y coordinates of the three triangle points.
662+
colors : (3, 4) array
663+
The RGBA values of the three triangle points.
664+
trans : `.Transform`
665+
"""
653666
# This uses a method described here:
654667
#
655668
# http://www.svgopen.org/2005/papers/Converting3DFaceToSVG/index.html
@@ -685,9 +698,9 @@ def draw_gouraud_triangle(self, gc, points, colors, trans):
685698
' \n1 1 1 1 0 \n0 0 0 0 1 ')
686699
writer.end('filter')
687700

688-
avg_color = np.sum(colors[:, :], axis=0) / 3.0
689-
# Just skip fully-transparent triangles
690-
if avg_color[-1] == 0.0:
701+
avg_color = np.average(colors, axis=0)
702+
if avg_color[-1] == 0:
703+
# Skip fully-transparent triangles
691704
return
692705

693706
trans_and_flip = self._make_flip_transform(trans)
@@ -698,7 +711,7 @@ def draw_gouraud_triangle(self, gc, points, colors, trans):
698711
x1, y1 = tpoints[i]
699712
x2, y2 = tpoints[(i + 1) % 3]
700713
x3, y3 = tpoints[(i + 2) % 3]
701-
c = colors[i][:]
714+
rgba_color = colors[i]
702715

703716
if x2 == x3:
704717
xb = x2
@@ -723,12 +736,13 @@ def draw_gouraud_triangle(self, gc, points, colors, trans):
723736
writer.element(
724737
'stop',
725738
offset='1',
726-
style=generate_css({'stop-color': rgb2hex(avg_color),
727-
'stop-opacity': short_float_fmt(c[-1])}))
739+
style=generate_css({
740+
'stop-color': rgb2hex(avg_color),
741+
'stop-opacity': short_float_fmt(rgba_color[-1])}))
728742
writer.element(
729743
'stop',
730744
offset='0',
731-
style=generate_css({'stop-color': rgb2hex(c),
745+
style=generate_css({'stop-color': rgb2hex(rgba_color),
732746
'stop-opacity': "0"}))
733747

734748
writer.end('linearGradient')

lib/matplotlib/patches.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3160,7 +3160,7 @@ def __call__(self, path, mutation_size, linewidth,
31603160
if aspect_ratio is not None:
31613161
# Squeeze the given height by the aspect_ratio
31623162

3163-
vertices, codes = path.vertices[:], path.codes[:]
3163+
vertices, codes = path.vertices.copy(), path.codes.copy()
31643164
# Squeeze the height
31653165
vertices[:, 1] = vertices[:, 1] / aspect_ratio
31663166
path_shrunk = Path(vertices, codes)

lib/matplotlib/widgets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2578,7 +2578,7 @@ def _press(self, event):
25782578
self._active_handle_idx = h_idx
25792579
# Save the vertex positions at the time of the press event (needed to
25802580
# support the 'move_all' state modifier).
2581-
self._xs_at_press, self._ys_at_press = self._xs[:], self._ys[:]
2581+
self._xs_at_press, self._ys_at_press = self._xs.copy(), self._ys.copy()
25822582

25832583
def _release(self, event):
25842584
"""Button release event handler"""

0 commit comments

Comments
 (0)