@@ -1345,9 +1345,12 @@ def findfont(self, prop, fontext='ttf', directory=None,
1345
1345
rc_params = tuple (tuple (mpl .rcParams [key ]) for key in [
1346
1346
"font.serif" , "font.sans-serif" , "font.cursive" , "font.fantasy" ,
1347
1347
"font.monospace" ])
1348
- return self ._findfont_cached (
1348
+ ret = self ._findfont_cached (
1349
1349
prop , fontext , directory , fallback_to_default , rebuild_if_missing ,
1350
1350
rc_params )
1351
+ if isinstance (ret , Exception ):
1352
+ raise ret
1353
+ return ret
1351
1354
1352
1355
def get_font_names (self ):
1353
1356
"""Return the list of available fonts."""
@@ -1443,7 +1446,6 @@ def _find_fonts_by_props(self, prop, fontext='ttf', directory=None,
1443
1446
except ValueError :
1444
1447
_log .warning ("findfont: Font family %r not found." , family )
1445
1448
1446
-
1447
1449
# only add default family if no other font was found and
1448
1450
# fallback_to_default is enabled
1449
1451
if not fpaths :
@@ -1517,8 +1519,9 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
1517
1519
return self .findfont (default_prop , fontext , directory ,
1518
1520
fallback_to_default = False )
1519
1521
else :
1520
- raise ValueError (f"Failed to find font { prop } , and fallback "
1521
- f"to the default font was disabled" )
1522
+ # yes return, exceptions are not cached
1523
+ return ValueError (f"Failed to find font { prop } , and fallback "
1524
+ f"to the default font was disabled" )
1522
1525
else :
1523
1526
_log .debug ('findfont: Matching %s to %s (%r) with score of %f.' ,
1524
1527
prop , best_font .name , best_font .fname , best_score )
@@ -1537,7 +1540,8 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
1537
1540
return self .findfont (
1538
1541
prop , fontext , directory , rebuild_if_missing = False )
1539
1542
else :
1540
- raise ValueError ("No valid font could be found" )
1543
+ # yes return, exceptions are not cached
1544
+ return ValueError ("No valid font could be found" )
1541
1545
1542
1546
return _cached_realpath (result )
1543
1547
0 commit comments