From eaae8a00086c3f253a292a3091e82442bf365ab6 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 17 Feb 2022 23:36:07 +0100 Subject: [PATCH] Don't key MathTextParser cache off a mutable FontProperties. See a46dd3b which recently did the same thing to _get_text_metrics_with_cache. Also, the comment was outdated. --- lib/matplotlib/mathtext.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/mathtext.py b/lib/matplotlib/mathtext.py index cdadcdbc9e6d..f94e1aa31bbf 100644 --- a/lib/matplotlib/mathtext.py +++ b/lib/matplotlib/mathtext.py @@ -233,9 +233,10 @@ def parse(self, s, dpi=72, prop=None): The results are cached, so multiple calls to `parse` with the same expression should be fast. """ - # lru_cache can't decorate parse() directly because the ps.useafm and - # mathtext.fontset rcParams also affect the parse (e.g. by affecting - # the glyph metrics). + # lru_cache can't decorate parse() directly because prop + # is mutable; key the cache using an internal copy (see + # text._get_text_metrics_with_cache for a similar case). + prop = prop.copy() if prop is not None else None return self._parse_cached(s, dpi, prop) @functools.lru_cache(50)