Skip to content

Commit 9d3b14c

Browse files
authored
Merge pull request #9070 from anntzer/no-renderer-uid
Replace use of renderer._uid by weakref.
2 parents d0eeddb + 8d22408 commit 9d3b14c

File tree

3 files changed

+2
-18
lines changed

3 files changed

+2
-18
lines changed

lib/matplotlib/backend_bases.py

-12
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
from functools import partial
4343
import importlib
4444
import io
45-
import itertools
4645
import os
4746
import sys
4847
import time
@@ -101,12 +100,6 @@
101100
}
102101

103102

104-
# Used to ensure that caching based on renderer id() is unique without being as
105-
# expensive as a real UUID. 0 is used for renderers that don't derive from
106-
# here, so start at 1.
107-
_unique_renderer_id = itertools.count(1)
108-
109-
110103
def register_backend(format, backend, description=None):
111104
"""
112105
Register a backend for saving to a given file format.
@@ -277,12 +270,7 @@ class RendererBase(object):
277270
278271
"""
279272
def __init__(self):
280-
# A lightweight id for unique-ification purposes. Along with id(self),
281-
# the combination should be unique enough to use as part of a cache key.
282-
self._uid = next(_unique_renderer_id)
283-
284273
self._texmanager = None
285-
286274
self._text2path = textpath.TextToPath()
287275

288276
def open_group(self, s, gid=None):

lib/matplotlib/backends/backend_mixed.py

-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import six
77

8-
import matplotlib.backend_bases
98
from matplotlib.backends.backend_agg import RendererAgg
109
from matplotlib.tight_bbox import process_figure_for_rasterizing
1110

@@ -50,9 +49,6 @@ def __init__(self, figure, width, height, dpi, vector_renderer,
5049
if raster_renderer_class is None:
5150
raster_renderer_class = RendererAgg
5251

53-
# See matplotlib.backend_bases.RendererBase._uid.
54-
self._uid = next(matplotlib.backend_bases._unique_renderer_id)
55-
5652
self._raster_renderer_class = raster_renderer_class
5753
self._width = width
5854
self._height = height

lib/matplotlib/text.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import math
1111
import warnings
12+
import weakref
1213

1314
import contextlib
1415

@@ -179,7 +180,6 @@ class Text(Artist):
179180
Handle storing and drawing of text in window or data coordinates.
180181
"""
181182
zorder = 3
182-
183183
_cached = maxdict(50)
184184

185185
def __repr__(self):
@@ -913,7 +913,7 @@ def get_prop_tup(self, renderer=None):
913913
self._verticalalignment, self._horizontalalignment,
914914
hash(self._fontproperties),
915915
self._rotation, self._rotation_mode,
916-
self.figure.dpi, id(renderer), getattr(renderer, '_uid', 0),
916+
self.figure.dpi, weakref.ref(renderer),
917917
self._linespacing
918918
)
919919

0 commit comments

Comments
 (0)