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