Skip to content

Commit d960244

Browse files
authored
Merge pull request #24230 from meeseeksmachine/auto-backport-of-pr-24229-on-v3.6.x
Backport PR #24229 on branch v3.6.x (FIX: do not mutate dictionaries passed in by user)
2 parents 0671809 + db433b5 commit d960244

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/matplotlib/figure.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,7 @@ def subplots(self, nrows=1, ncols=1, *, sharex=False, sharey=False,
878878
# Note that this is the same as
879879
fig.subplots(2, 2, sharex=True, sharey=True)
880880
"""
881-
if gridspec_kw is None:
882-
gridspec_kw = {}
881+
gridspec_kw = dict(gridspec_kw or {})
883882
if height_ratios is not None:
884883
if 'height_ratios' in gridspec_kw:
885884
raise ValueError("'height_ratios' must not be defined both as "
@@ -1869,7 +1868,7 @@ def subplot_mosaic(self, mosaic, *, sharex=False, sharey=False,
18691868
18701869
"""
18711870
subplot_kw = subplot_kw or {}
1872-
gridspec_kw = gridspec_kw or {}
1871+
gridspec_kw = dict(gridspec_kw or {})
18731872
if height_ratios is not None:
18741873
if 'height_ratios' in gridspec_kw:
18751874
raise ValueError("'height_ratios' must not be defined both as "

lib/matplotlib/tests/test_figure.py

+8
Original file line numberDiff line numberDiff line change
@@ -1412,3 +1412,11 @@ def test_unpickle_with_device_pixel_ratio():
14121412
assert fig.dpi == 42*7
14131413
fig2 = pickle.loads(pickle.dumps(fig))
14141414
assert fig2.dpi == 42
1415+
1416+
1417+
def test_gridspec_no_mutate_input():
1418+
gs = {'left': .1}
1419+
gs_orig = dict(gs)
1420+
plt.subplots(1, 2, width_ratios=[1, 2], gridspec_kw=gs)
1421+
assert gs == gs_orig
1422+
plt.subplot_mosaic('AB', width_ratios=[1, 2], gridspec_kw=gs)

0 commit comments

Comments
 (0)