Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eaae8a0

Browse files
committed
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.
1 parent 3c6efec commit eaae8a0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/matplotlib/mathtext.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,10 @@ def parse(self, s, dpi=72, prop=None):
233233
The results are cached, so multiple calls to `parse`
234234
with the same expression should be fast.
235235
"""
236-
# lru_cache can't decorate parse() directly because the ps.useafm and
237-
# mathtext.fontset rcParams also affect the parse (e.g. by affecting
238-
# the glyph metrics).
236+
# lru_cache can't decorate parse() directly because prop
237+
# is mutable; key the cache using an internal copy (see
238+
# text._get_text_metrics_with_cache for a similar case).
239+
prop = prop.copy() if prop is not None else None
239240
return self._parse_cached(s, dpi, prop)
240241

241242
@functools.lru_cache(50)

0 commit comments

Comments
 (0)