Skip to content

Commit 99aeb16

Browse 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 a1cd412 commit 99aeb16

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/matplotlib/font_manager.py

Lines changed: 9 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,9 @@ 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+
# yes return, exceptions are not cached
1503+
return ValueError(f"Failed to find font {prop}, and fallback "
1504+
f"to the default font was disabled")
15011505
else:
15021506
_log.debug('findfont: Matching %s to %s (%r) with score of %f.',
15031507
prop, best_font.name, best_font.fname, best_score)
@@ -1516,7 +1520,8 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
15161520
return self.findfont(
15171521
prop, fontext, directory, rebuild_if_missing=False)
15181522
else:
1519-
raise ValueError("No valid font could be found")
1523+
# yes return, exceptions are not cached
1524+
return ValueError("No valid font could be found")
15201525

15211526
return _cached_realpath(result)
15221527

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy