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 6e99a52

Browse filesBrowse files
tacaswellQuLogic
authored andcommitted
FIX: do not raise in lru_cached function
If the cached function raises it will not be cached and we will continuously pay for cache misses.
1 parent a0fcf79 commit 6e99a52
Copy full SHA for 6e99a52

File tree

Expand file treeCollapse file tree

1 file changed

+13
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-4
lines changed

‎lib/matplotlib/font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/font_manager.py
+13-4Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,9 +1345,12 @@ def findfont(self, prop, fontext='ttf', directory=None,
13451345
rc_params = tuple(tuple(mpl.rcParams[key]) for key in [
13461346
"font.serif", "font.sans-serif", "font.cursive", "font.fantasy",
13471347
"font.monospace"])
1348-
return self._findfont_cached(
1348+
ret = self._findfont_cached(
13491349
prop, fontext, directory, fallback_to_default, rebuild_if_missing,
13501350
rc_params)
1351+
if isinstance(ret, Exception):
1352+
raise ret
1353+
return ret
13511354

13521355
def get_font_names(self):
13531356
"""Return the list of available fonts."""
@@ -1496,8 +1499,11 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
14961499
return self.findfont(default_prop, fontext, directory,
14971500
fallback_to_default=False)
14981501
else:
1499-
raise ValueError(f"Failed to find font {prop}, and fallback "
1500-
f"to the default font was disabled")
1502+
# This return instead of raise is intentional, as we wish to
1503+
# cache the resulting exception, which will not occur if it was
1504+
# actually raised.
1505+
return ValueError(f"Failed to find font {prop}, and fallback "
1506+
f"to the default font was disabled")
15011507
else:
15021508
_log.debug('findfont: Matching %s to %s (%r) with score of %f.',
15031509
prop, best_font.name, best_font.fname, best_score)
@@ -1516,7 +1522,10 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
15161522
return self.findfont(
15171523
prop, fontext, directory, rebuild_if_missing=False)
15181524
else:
1519-
raise ValueError("No valid font could be found")
1525+
# This return instead of raise is intentional, as we wish to
1526+
# cache the resulting exception, which will not occur if it was
1527+
# actually raised.
1528+
return ValueError("No valid font could be found")
15201529

15211530
return _cached_realpath(result)
15221531

0 commit comments

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