Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8d22408

Browse files
committed
Replace use of renderer._uid by weakref.
This avoids the need for a note regarding issues with renderer classes that do not inherit from RendererBase. Remember that the goal of _uid was to prevent two renderers from sharing the same id() even though they were actually different (if one has been GC'd and another is created at the same address). Maintaining a weakref to the renderer works as well, as weakref equality is thusly defined: If the referents are still alive, two references have the same equality relationship as their referents (regardless of the callback). If either referent has been deleted, the references are equal only if the reference objects are the same object.
1 parent 6a91a4e commit 8d22408

File tree

4 files changed

+2
-29
lines changed

4 files changed

+2
-29
lines changed

doc/api/api_changes/2017-06-03-ES_unique_renderer.rst

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/matplotlib/backend_bases.py

Lines changed: 0 additions & 12 deletions
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

Lines changed: 0 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

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

186186
def __repr__(self):
@@ -912,7 +912,7 @@ def get_prop_tup(self, renderer=None):
912912
self._verticalalignment, self._horizontalalignment,
913913
hash(self._fontproperties),
914914
self._rotation, self._rotation_mode,
915-
self.figure.dpi, id(renderer), getattr(renderer, '_uid', 0),
915+
self.figure.dpi, weakref.ref(renderer),
916916
self._linespacing
917917
)
918918

0 commit comments

Comments
 (0)