Skip to content

Commit f2fabc0

Browse files
authored
Merge pull request #6821 from anntzer/break-line-refcycle
MNT: Break reference cycle Line2D <-> Line2D._lineFunc.
2 parents e6fccba + 64479b4 commit f2fabc0

File tree

2 files changed

+2
-25
lines changed

2 files changed

+2
-25
lines changed

lib/matplotlib/lines.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,6 @@ def __init__(self, xdata, ydata,
445445

446446
self.set_data(xdata, ydata)
447447

448-
def __getstate__(self):
449-
state = super(Line2D, self).__getstate__()
450-
# _linefunc will be restored on draw time.
451-
state.pop('_lineFunc', None)
452-
return state
453-
454448
def contains(self, mouseevent):
455449
"""
456450
Test whether the mouse event occurred on the line. The pick
@@ -784,7 +778,7 @@ def draw(self, renderer):
784778
if funcname != '_draw_nothing':
785779
tpath, affine = transf_path.get_transformed_path_and_affine()
786780
if len(tpath.vertices):
787-
self._lineFunc = getattr(self, funcname)
781+
line_func = getattr(self, funcname)
788782
gc = renderer.new_gc()
789783
self._set_gc_clip(gc)
790784

@@ -807,7 +801,7 @@ def draw(self, renderer):
807801
if self.get_sketch_params() is not None:
808802
gc.set_sketch_params(*self.get_sketch_params())
809803

810-
self._draw_lines(renderer, gc, tpath, affine.frozen())
804+
line_func(renderer, gc, tpath, affine.frozen())
811805
gc.restore()
812806

813807
if self._marker and self._markersize > 0:
@@ -1250,9 +1244,6 @@ def set_dashes(self, seq):
12501244
else:
12511245
self.set_linestyle((0, seq))
12521246

1253-
def _draw_lines(self, renderer, gc, path, trans):
1254-
self._lineFunc(renderer, gc, path, trans)
1255-
12561247
def _draw_solid(self, renderer, gc, path, trans):
12571248
gc.set_linestyle('solid')
12581249
gc.set_dashes(self._dashOffset, self._dashSeq)

lib/matplotlib/tests/test_pickle.py

-14
Original file line numberDiff line numberDiff line change
@@ -228,20 +228,6 @@ def test_image():
228228
pickle.dump(fig, BytesIO())
229229

230230

231-
@cleanup
232-
def test_grid():
233-
from matplotlib.backends.backend_agg import new_figure_manager
234-
manager = new_figure_manager(1000)
235-
fig = manager.canvas.figure
236-
ax = fig.add_subplot(1, 1, 1)
237-
ax.grid()
238-
# Drawing the grid triggers instance methods to be attached
239-
# to the Line2D object (_lineFunc).
240-
manager.canvas.draw()
241-
242-
pickle.dump(ax, BytesIO())
243-
244-
245231
@cleanup
246232
def test_polar():
247233
ax = plt.subplot(111, polar=True)

0 commit comments

Comments
 (0)