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 5c9d97e

Browse filesBrowse files
committed
MNT: Update lru_cache to cache where appropriate
1 parent c26270b commit 5c9d97e
Copy full SHA for 5c9d97e

File tree

11 files changed

+19
-19
lines changed
Filter options

11 files changed

+19
-19
lines changed

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def _check_versions():
231231

232232
# The decorator ensures this always returns the same handler (and it is only
233233
# attached once).
234-
@functools.lru_cache
234+
@functools.cache
235235
def _ensure_handler():
236236
"""
237237
The first time this function is called, attach a `StreamHandler` using the
@@ -321,7 +321,7 @@ class ExecutableNotFoundError(FileNotFoundError):
321321
pass
322322

323323

324-
@functools.lru_cache
324+
@functools.cache
325325
def _get_executable_info(name):
326326
"""
327327
Get the version of some executable that Matplotlib optionally depends on.
@@ -799,7 +799,7 @@ def rc_params(fail_on_error=False):
799799
return rc_params_from_file(matplotlib_fname(), fail_on_error)
800800

801801

802-
@functools.lru_cache
802+
@functools.cache
803803
def _get_ssl_context():
804804
try:
805805
import certifi

‎lib/matplotlib/_api/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_api/__init__.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def name(self): ...
219219
if isinstance(prop, property)}
220220
instance = cls()
221221

222-
@functools.lru_cache(None)
222+
@functools.cache
223223
def __getattr__(name):
224224
if name in props:
225225
return props[name].__get__(instance)

‎lib/matplotlib/_mathtext.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_mathtext.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class TruetypeFonts(Fonts):
273273
def __init__(self, *args, **kwargs):
274274
super().__init__(*args, **kwargs)
275275
# Per-instance cache.
276-
self._get_info = functools.lru_cache(None)(self._get_info)
276+
self._get_info = functools.cache(self._get_info)
277277
self._fonts = {}
278278

279279
filename = findfont(self.default_font_prop)
@@ -752,7 +752,7 @@ def _map_virtual_font(self, fontname, font_class, uniindex):
752752

753753
return fontname, uniindex
754754

755-
@functools.lru_cache
755+
@functools.cache
756756
def get_sized_alternatives_for_symbol(self, fontname, sym):
757757
fixes = {
758758
'\\{': '{', '\\}': '}', '\\[': '[', '\\]': ']',

‎lib/matplotlib/artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections import namedtuple
22
import contextlib
3-
from functools import lru_cache, wraps
3+
from functools import cache, wraps
44
import inspect
55
from inspect import Signature, Parameter
66
import logging
@@ -1538,13 +1538,13 @@ def get_setters(self):
15381538
return setters
15391539

15401540
@staticmethod
1541-
@lru_cache(maxsize=None)
1541+
@cache
15421542
def number_of_parameters(func):
15431543
"""Return number of parameters of the callable *func*."""
15441544
return len(inspect.signature(func).parameters)
15451545

15461546
@staticmethod
1547-
@lru_cache(maxsize=None)
1547+
@cache
15481548
def is_alias(method):
15491549
"""
15501550
Return whether the object *method* is an alias for another method.

‎lib/matplotlib/backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_bases.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,12 +1695,12 @@ def __init__(self, figure=None):
16951695
scroll_pick_id = property(lambda self: self.figure._scroll_pick_id)
16961696

16971697
@classmethod
1698-
@functools.lru_cache
1698+
@functools.cache
16991699
def _fix_ipython_backend2gui(cls):
17001700
# Fix hard-coded module -> toolkit mapping in IPython (used for
17011701
# `ipython --auto`). This cannot be done at import time due to
17021702
# ordering issues, so we do it when creating a canvas, and should only
1703-
# be done once per class (hence the `lru_cache(1)`).
1703+
# be done once per class (hence the `cache`).
17041704
if sys.modules.get("IPython") is None:
17051705
return
17061706
import IPython

‎lib/matplotlib/backends/backend_ps.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_ps.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def __init__(self, width, height, pswriter, imagedpi=72):
289289
self._path_collection_id = 0
290290

291291
self._character_tracker = _backend_pdf_ps.CharacterTracker()
292-
self._logwarn_once = functools.lru_cache(None)(_log.warning)
292+
self._logwarn_once = functools.cache(_log.warning)
293293

294294
def _is_transparent(self, rgb_or_rgba):
295295
if rgb_or_rgba is None:

‎lib/matplotlib/backends/qt_compat.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/qt_compat.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _isdeleted(obj):
158158
# PyQt6 enum compat helpers.
159159

160160

161-
@functools.lru_cache(None)
161+
@functools.cache
162162
def _enum(name):
163163
# foo.bar.Enum.Entry (PyQt6) <=> foo.bar.Entry (non-PyQt6).
164164
return operator.attrgetter(

‎lib/matplotlib/cbook.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@ def _unikey_or_keysym_to_mplkey(unikey, keysym):
21782178
return key
21792179

21802180

2181-
@functools.lru_cache(None)
2181+
@functools.cache
21822182
def _make_class_factory(mixin_class, fmt, attr_name=None):
21832183
"""
21842184
Return a function that creates picklable classes inheriting from a mixin.
@@ -2197,7 +2197,7 @@ def _make_class_factory(mixin_class, fmt, attr_name=None):
21972197
``Axes`` class always return the same subclass.
21982198
"""
21992199

2200-
@functools.lru_cache(None)
2200+
@functools.cache
22012201
def class_factory(axes_class):
22022202
# if we have already wrapped this class, declare victory!
22032203
if issubclass(axes_class, mixin_class):

‎lib/matplotlib/colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colors.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,7 @@ def init(vmin=None, vmax=None, clip=False): pass
16231623
base_norm_cls, inspect.signature(init))
16241624

16251625

1626-
@functools.lru_cache(None)
1626+
@functools.cache
16271627
def _make_norm_from_scale(
16281628
scale_cls, scale_args, scale_kwargs_items,
16291629
base_norm_cls, bound_init_signature,

‎lib/matplotlib/testing/compare.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/compare.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def _clean_conversion_cache():
339339
path.unlink()
340340

341341

342-
@functools.lru_cache # Ensure this is only registered once.
342+
@functools.cache # Ensure this is only registered once.
343343
def _register_conversion_cache_cleaner_once():
344344
atexit.register(_clean_conversion_cache)
345345

‎setupext.py

Copy file name to clipboardExpand all lines: setupext.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _get_hash(data):
4343
return hasher.hexdigest()
4444

4545

46-
@functools.lru_cache
46+
@functools.cache
4747
def _get_ssl_context():
4848
import certifi
4949
import ssl
@@ -229,7 +229,7 @@ def print_status(package, status):
229229
subsequent_indent=indent))
230230

231231

232-
@functools.lru_cache(1) # We only need to compute this once.
232+
@functools.cache # We only need to compute this once.
233233
def get_pkg_config():
234234
"""
235235
Get path to pkg-config and set up the PKG_CONFIG environment variable.

0 commit comments

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