@@ -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