Skip to content

Navigation Menu

Sign in
Appearance settings

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 2005738

Browse filesBrowse files
committed
Use itertools.count for renderer unique ID.
As suggested by @anntzer.
1 parent e050729 commit 2005738
Copy full SHA for 2005738

File tree

Expand file treeCollapse file tree

2 files changed

+12
-30
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-30
lines changed

‎lib/matplotlib/backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_bases.py
+8-17Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from contextlib import contextmanager
4242
import importlib
4343
import io
44+
import itertools
4445
import os
4546
import sys
4647
import time
@@ -101,8 +102,9 @@
101102

102103

103104
# Used to ensure that caching based on renderer id() is unique without being as
104-
# expensive as a real UUID.
105-
_unique_renderer_id = 0
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)
106108

107109

108110
def register_backend(format, backend, description=None):
@@ -217,25 +219,14 @@ class RendererBase(object):
217219
218220
"""
219221
def __init__(self):
220-
self._id = None
222+
# A lightweight id for unique-ification purposes. Along with id(self),
223+
# the combination should be unique enough to use as part of a cache key.
224+
self._uid = next(_unique_renderer_id)
225+
221226
self._texmanager = None
222227

223228
self._text2path = textpath.TextToPath()
224229

225-
@property
226-
def _uid(self):
227-
"""
228-
A lightweight id for unique-ification purposes.
229-
230-
Along with id(self), this combination should be unique enough to use as
231-
part of a caching key.
232-
"""
233-
if self._id is None:
234-
global _unique_renderer_id
235-
_unique_renderer_id += 1
236-
self._id = _unique_renderer_id
237-
return self._id
238-
239230
def open_group(self, s, gid=None):
240231
"""
241232
Open a grouping element with label *s*. If *gid* is given, use

‎lib/matplotlib/backends/backend_mixed.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_mixed.py
+4-13Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import six
77

8+
import matplotlib.backend_bases
89
from matplotlib.backends.backend_agg import RendererAgg
910
from matplotlib.tight_bbox import process_figure_for_rasterizing
1011

@@ -49,7 +50,9 @@ def __init__(self, figure, width, height, dpi, vector_renderer,
4950
if raster_renderer_class is None:
5051
raster_renderer_class = RendererAgg
5152

52-
self._id = None
53+
# See matplotlib.backend_bases.RendererBase._uid.
54+
self._uid = next(matplotlib.backend_bases._unique_renderer_id)
55+
5356
self._raster_renderer_class = raster_renderer_class
5457
self._width = width
5558
self._height = height
@@ -81,18 +84,6 @@ def __init__(self, figure, width, height, dpi, vector_renderer,
8184
_text2path _get_text_path_transform height width
8285
""".split()
8386

84-
@property
85-
def _uid(self):
86-
"""
87-
See matplotlib.backend_bases.RendererBase._uid.
88-
"""
89-
if self._id is None:
90-
from matplotlib import backend_bases
91-
backend_bases._unique_renderer_id
92-
backend_bases._unique_renderer_id += 1
93-
self._id = backend_bases._unique_renderer_id
94-
return self._id
95-
9687
def _set_current_renderer(self, renderer):
9788
self._renderer = renderer
9889

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.