8000 Use parentheses for multi-line context expressions · matplotlib/matplotlib@20b9b1e · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 20b9b1e

Browse files
committed
Use parentheses for multi-line context expressions
Now allowed in Python 3.10.
1 parent 3e9291f commit 20b9b1e

File tree

10 files changed

+34
-37
lines changed

10 files changed

+34
-37
lines changed

lib/matplotlib/animation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,8 @@ def _pre_composite_to_white(color):
10861086
# canvas._is_saving = True makes the draw_event animation-starting
10871087
# callback a no-op; canvas.manager = None prevents resizing the GUI
10881088
# widget (both are likewise done in savefig()).
1089-
with writer.saving(self._fig, filename, dpi), \
1090-
cbook._setattr_cm(self._fig.canvas, _is_saving=True, manager=None):
1089+
with (writer.saving(self._fig, filename, dpi),
1090+
cbook._setattr_cm(self._fig.canvas, _is_saving=True, manager=None)):
10911091
for anim in all_anim:
10921092
anim._init_draw() # Clear the initial frame
10931093
frame_number = 0

lib/matplotlib/backend_bases.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,8 +1972,8 @@ def _switch_canvas_and_return_print_method(self, fmt, backend=None):
19721972
"""
19731973
Context manager temporarily setting the canvas for saving the figure::
19741974
1975-
with canvas._switch_canvas_and_return_print_method(fmt, backend) \\
1976-
as print_method:
1975+
with (canvas._switch_canvas_and_return_print_method(fmt, backend)
1976+
as print_method):
19771977
# ``print_method`` is a suitable ``print_{fmt}`` method, and
19781978
# the figure's canvas is temporarily switched to the method's
19791979
# canvas within the with... block. ``print_method`` is also
@@ -2110,13 +2110,13 @@ def print_figure(
21102110
"'figure', or omit the *papertype* argument entirely.")
21112111

21122112
# Remove the figure manager, if any, to avoid resizing the GUI widget.
2113-
with cbook._setattr_cm(self, manager=None), \
2114-
self._switch_canvas_and_return_print_method(format, backend) \
2115-
as print_method, \
2116-
cbook._setattr_cm(self.figure, dpi=dpi), \
2117-
cbook._setattr_cm(self.figure.canvas, _device_pixel_ratio=1), \
2118-
cbook._setattr_cm(self.figure.canvas, _is_saving=True), \
2119-
ExitStack() as stack:
2113+
with (cbook._setattr_cm(self, manager=None),
2114+
self._switch_canvas_and_return_print_method(format, backend)
2115+
as print_method,
2116+
cbook._setattr_cm(self.figure, dpi=dpi),
2117+
cbook._setattr_cm(self.figure.canvas, _device_pixel_ratio=1),
2118+
cbook._setattr_cm(self.figure.canvas, _is_saving=True),
2119+
ExitStack() as stack):
21202120

21212121
for prop in ["facecolor", "edgecolor"]:
21222122
color = locals()[prop]

lib/matplotlib/backend_tools.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ def trigger(self, sender, event, data=None):
382382
sentinel = str(uuid.uuid4())
383383
# Trigger grid switching by temporarily setting :rc:`keymap.grid`
384384
# to a unique key and sending an appropriate event.
385-
with cbook._setattr_cm(event, key=sentinel), \
386-
mpl.rc_context({'keymap.grid': sentinel}):
385+
with (cbook._setattr_cm(event, key=sentinel),
386+
mpl.rc_context({'keymap.grid': sentinel})):
387387
mpl.backend_bases.key_press_handler(event, self.figure.canvas)
388388

389389

@@ -397,8 +397,8 @@ def trigger(self, sender, event, data=None):
397397
sentinel = str(uuid.uuid4())
398398
# Trigger grid switching by temporarily setting :rc:`keymap.grid_minor`
399399
# to a unique key and sending an appropriate event.
400-
with cbook._setattr_cm(event, key=sentinel), \
401-
mpl.rc_context({'keymap.grid_minor': sentinel}):
400+
with (cbook._setattr_cm(event, key=sentinel),
401+
mpl.rc_context({'keymap.grid_minor': sentinel})):
402402
mpl.backend_bases.key_press_handler(event, self.figure.canvas)
403403

404404

lib/matplotlib/backends/backend_pgf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,8 @@ def print_pdf(self, fname_or_fh, *, metadata=None, **kwargs):
849849
cbook._check_and_log_subprocess(
850850
[texcommand, "-interaction=nonstopmode", "-halt-on-error",
851851
"figure.tex"], _log, cwd=tmpdir)
852-
with (tmppath / "figure.pdf").open("rb") as orig, \
853-
cbook.open_file_cm(fname_or_fh, "wb") as dest:
852+
with ((tmppath / "figure.pdf").open("rb") as orig,
853+
cbook.open_file_cm(fname_or_fh, "wb") as dest):
854854
shutil.copyfileobj(orig, dest) # copy file contents to target
855855

856856
def print_png(self, fname_or_fh, **kwargs):
@@ -862,8 +862,8 @@ def print_png(self, fname_or_fh, **kwargs):
862862
png_path = tmppath / "figure.png"
863863
self.print_pdf(pdf_path, **kwargs)
864864
converter(pdf_path, png_path, dpi=self.figure.dpi)
865-
with png_path.open("rb") as orig, \
866-
cbook.open_file_cm(fname_or_fh, "wb") as dest:
865+
with (png_path.open("rb") as orig,
866+
cbook.open_file_cm(fname_or_fh, "wb") as dest):
867867
shutil.copyfileobj(orig, dest) # copy file contents to target
868868

869869
def get_renderer(self):

lib/matplotlib/backends/backend_svg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,8 +1356,8 @@ def print_svg(self, filename, *, bbox_inches_restore=None, metadata=None):
13561356
renderer.finalize()
13571357

13581358
def print_svgz(self, filename, **kwargs):
1359-
with cbook.open_file_cm(filename, "wb") as fh, \
1360-
gzip.GzipFile(mode='w', fileobj=fh) as gzipwriter:
1359+
with (cbook.open_file_cm(filename, "wb") as fh,
1360+
gzip.GzipFile(mode='w', fileobj=fh) as gzipwriter):
13611361
return self.print_svg(gzipwriter, **kwargs)
13621362

13631363
def get_default_filetype(self):

lib/matplotlib/colorbar.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,10 +1115,8 @@ def _mesh(self):
11151115
# Update the norm values in a context manager as it is only
11161116
# a temporary change and we don't want to propagate any signals
11171117
# attached to the norm (callbacks.blocked).
1118-
with self.norm.callbacks.blocked(), \
1119-
cbook._setattr_cm(self.norm,
1120-
vmin=self.vmin,
1121-
vmax=self.vmax):
1118+
with (self.norm.callbacks.blocked(),
1119+
cbook._setattr_cm(self.norm, vmin=self.vmin, vmax=self.vmax)):
11221120
y = self.norm.inverse(y)
11231121
self._y = y
11241122
X, Y = np.meshgrid([0., 1.], y)

lib/matplotlib/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,8 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
576576
s_vmin = np.finfo(scaled_dtype).eps
577577
# Block the norm from sending an update signal during the
578578
# temporary vmin/vmax change
579-
with self.norm.callbacks.blocked(), \
580-
cbook._setattr_cm(self.norm, vmin=s_vmin, vmax=s_vmax):
579+
with (self.norm.callbacks.blocked(),
580+
cbook._setattr_cm(self.norm, vmin=s_vmin, vmax=s_vmax)):
581581
output = self.norm(resampled_masked)
582582
else:
583583
if A.ndim == 2: # interpolation_stage = 'rgba'

lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ def test_multipage_keep_empty(tmp_path):
9191

9292
# an empty pdf is left behind with keep_empty=True
9393
fn = tmp_path / "b.pdf"
94-
with pytest.warns(mpl.MatplotlibDeprecationWarning), \
95-
PdfPages(fn, keep_empty=True) as pdf:
94+
with (pytest.warns(mpl.MatplotlibDeprecationWarning),
95+
PdfPages(fn, keep_empty=True) as pdf):
9696
pass
9797
assert fn.exists()
9898

@@ -112,8 +112,8 @@ def test_multipage_keep_empty(tmp_path):
112112

113113
# a non-empty pdf is left behind with keep_empty=True
114114
fn = tmp_path / "e.pdf"
115-
with pytest.warns(mpl.MatplotlibDeprecationWarning), \
116-
PdfPages(fn, keep_empty=True) as pdf:
115+
with (pytest.warns(mpl.MatplotlibDeprecationWarning),
116+
PdfPages(fn, keep_empty=True) as pdf):
117117
pdf.savefig(plt.figure())
118118
assert fn.exists()
119119

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ def test_multipage_keep_empty(tmp_path):
298298

299299
# an empty pdf is left behind with keep_empty=True
300300
fn = tmp_path / "b.pdf"
301-
with pytest.warns(mpl.MatplotlibDeprecationWarning), \
302-
PdfPages(fn, keep_empty=True) as pdf:
301+
with (pytest.warns(mpl.MatplotlibDeprecationWarning),
302+
PdfPages(fn, keep_empty=True) as pdf):
303303
pass
304304
assert fn.exists()
305305

@@ -319,8 +319,8 @@ def test_multipage_keep_empty(tmp_path):
319319

320320
# a non-empty pdf is left behind with keep_empty=True
321321
fn = tmp_path / "e.pdf"
322-
with pytest.warns(mpl.MatplotlibDeprecationWarning), \
323-
PdfPages(fn, keep_empty=True) as pdf:
322+
with (pytest.warns(mpl.MatplotlibDeprecationWarning),
323+
PdfPages(fn, keep_empty=True) as pdf):
324324
pdf.savefig(plt.figure())
325325
assert fn.exists()
326326

lib/matplotlib/tests/test_cbook.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,7 @@ def test_sanitize_sequence():
466466

467467
@pytest.mark.parametrize('inp, kwargs_to_norm', fail_mapping)
468468
def test_normalize_kwargs_fail(inp, kwargs_to_norm):
469-
with pytest.raises(TypeError), \
470-
_api.suppress_matplotlib_deprecation_warning():
469+
with pytest.raises(TypeError), _api.suppress_matplotlib_deprecation_warning():
471470
cbook.normalize_kwargs(inp, **kwargs_to_norm)
472471

473472

0 commit comments

Comments
 (0)
0