Skip to content

Commit 8a543b5

Browse files
committed
In findfont(fallback_to_default=False), throw if default font is missing.
... instead of entering an infinite loop of findfont -> defaultFont -> findfont. A bit of a pain to test (one needs to delete dejavusans both from the mpl source tree and from the system font folder)... This should only affect people who delete the default fonts anyways (or call with fallback_to_default=False), so I'll skip the API change note.
1 parent cbd0409 commit 8a543b5

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

lib/matplotlib/font_manager.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,11 +1284,8 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
12841284
default_prop.set_family(self.defaultFamily[fontext])
12851285
return self.findfont(default_prop, fontext, directory, False)
12861286
else:
1287-
# This is a hard fail -- we can't find anything reasonable,
1288-
# so just return the DejaVuSans.ttf
1289-
_log.warning('findfont: Could not match %s. Returning %s.',
1290-
prop, self.defaultFont[fontext])
1291-
result = self.defaultFont[fontext]
1287+
raise ValueError(f"Failed to find font {prop}, and fallback "
1288+
f"to the default font was disabled")
12921289
else:
12931290
_log.debug('findfont: Matching %s to %s (%r) with score of %f.',
12941291
prop, best_font.name, best_font.fname, best_score)

0 commit comments

Comments
 (0)