Skip to content

Commit 2eb851a

Browse files
authored
Merge pull request #18845 from QuLogic/auto-backport-of-pr-18839-on-v3.3.x
Backport PR #18839 on branch v3.3.x
2 parents bef11fb + c8324ee commit 2eb851a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/matplotlib/tests/test_text.py

+12
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
import matplotlib as mpl
1010
from matplotlib.backend_bases import MouseEvent
11+
from matplotlib.font_manager import FontProperties
1112
import matplotlib.patches as mpatches
1213
import matplotlib.pyplot as plt
1314
from matplotlib.testing.decorators import check_figures_equal, image_comparison
15+
from matplotlib.text import Text
1416

1517

1618
needs_usetex = pytest.mark.skipif(
@@ -689,3 +691,13 @@ def test_fontproperties_kwarg_precedence():
689691
text2 = plt.ylabel("counts", size=40.0, fontproperties='Times New Roman')
690692
assert text1.get_size() == 40.0
691693
assert text2.get_size() == 40.0
694+
695+
696+
def test_update_mutate_input():
697+
inp = dict(fontproperties=FontProperties(weight="bold"),
698+
bbox=None)
699+
cache = dict(inp)
700+
t = Text()
701+
t.update(inp)
702+
assert inp['fontproperties'] == cache['fontproperties']
703+
assert inp['bbox'] == cache['bbox']

lib/matplotlib/text.py

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ def __init__(self,
167167

168168
def update(self, kwargs):
169169
# docstring inherited
170+
# make a copy so we do not mutate user input!
171+
kwargs = dict(kwargs)
170172
sentinel = object() # bbox can be None, so use another sentinel.
171173
# Update fontproperties first, as it has lowest priority.
172174
fontproperties = kwargs.pop("fontproperties", sentinel)

0 commit comments

Comments
 (0)