Skip to content

Commit bfdbb94

Browse files
authored
Merge pull request #19487 from anntzer/noargs
Deprecate unused \*args to print_<foo>.
2 parents ff3a0e4 + 0c75f8f commit bfdbb94

File tree

7 files changed

+24
-14
lines changed

7 files changed

+24
-14
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Unused positional parameters to ``print_<fmt>`` methods are deprecated
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
None of the ``print_<fmt>`` methods implemented by canvas subclasses used
5+
positional arguments other that the first (the output filename or file-like),
6+
so these extra parameters are deprecated.

lib/matplotlib/backends/backend_agg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ def buffer_rgba(self):
448448
return self.renderer.buffer_rgba()
449449

450450
@_check_savefig_extra_args
451+
@_api.delete_parameter("3.5", "args")
451452
def print_raw(self, filename_or_obj, *args):
452453
FigureCanvasAgg.draw(self)
453454
renderer = self.get_renderer()
@@ -457,6 +458,7 @@ def print_raw(self, filename_or_obj, *args):
457458
print_rgba = print_raw
458459

459460
@_check_savefig_extra_args
461+
@_api.delete_parameter("3.5", "args")
460462
def print_png(self, filename_or_obj, *args,
461463
metadata=None, pil_kwargs=None):
462464
"""
@@ -528,6 +530,7 @@ def print_to_buffer(self):
528530
alternative="pil_kwargs={'optimize': ...}")
529531
@_api.delete_parameter("3.3", "progressive",
530532
alternative="pil_kwargs={'progressive': ...}")
533+
@_api.delete_parameter("3.5", "args")
531534
def print_jpg(self, filename_or_obj, *args, pil_kwargs=None, **kwargs):
532535
"""
533536
Write the figure to a JPEG file.

lib/matplotlib/backends/backend_gtk3agg.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ def draw(self):
7070
backend_agg.FigureCanvasAgg.draw(self)
7171
super().draw()
7272

73-
def print_png(self, filename, *args, **kwargs):
74-
# Do this so we can save the resolution of figure in the PNG file
75-
agg = self.switch_backends(backend_agg.FigureCanvasAgg)
76-
return agg.print_png(filename, *args, **kwargs)
77-
7873

7974
class FigureManagerGTK3Agg(backend_gtk3.FigureManagerGTK3):
8075
pass

lib/matplotlib/backends/backend_pgf.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -843,17 +843,17 @@ def _print_pgf_to_fh(self, fh, *, bbox_inches_restore=None):
843843
writeln(fh, r"\makeatother")
844844
writeln(fh, r"\endgroup")
845845

846-
def print_pgf(self, fname_or_fh, *args, **kwargs):
846+
def print_pgf(self, fname_or_fh, **kwargs):
847847
"""
848848
Output pgf macros for drawing the figure so it can be included and
849849
rendered in latex documents.
850850
"""
851851
with cbook.open_file_cm(fname_or_fh, "w", encoding="utf-8") as file:
852852
if not cbook.file_requires_unicode(file):
853853
file = codecs.getwriter("utf-8")(file)
854-
self._print_pgf_to_fh(file, *args, **kwargs)
854+
self._print_pgf_to_fh(file, **kwargs)
855855

856-
def print_pdf(self, fname_or_fh, *args, metadata=None, **kwargs):
856+
def print_pdf(self, fname_or_fh, *, metadata=None, **kwargs):
857857
"""Use LaTeX to compile a pgf generated figure to pdf."""
858858
w, h = self.figure.get_figwidth(), self.figure.get_figheight()
859859

@@ -865,7 +865,7 @@ def print_pdf(self, fname_or_fh, *args, metadata=None, **kwargs):
865865
tmppath = pathlib.Path(tmpdir)
866866

867867
# print figure to pgf and compile it with latex
868-
self.print_pgf(tmppath / "figure.pgf", *args, **kwargs)
868+
self.print_pgf(tmppath / "figure.pgf", **kwargs)
869869

870870
latexcode = """
871871
\\PassOptionsToPackage{pdfinfo={%s}}{hyperref}
@@ -891,14 +891,14 @@ def print_pdf(self, fname_or_fh, *args, metadata=None, **kwargs):
891891
cbook.open_file_cm(fname_or_fh, "wb") as dest:
892892
shutil.copyfileobj(orig, dest) # copy file contents to target
893893

894-
def print_png(self, fname_or_fh, *args, **kwargs):
894+
def print_png(self, fname_or_fh, **kwargs):
895895
"""Use LaTeX to compile a pgf figure to pdf and convert it to png."""
896896
converter = make_pdf_to_png_converter()
897897
with TemporaryDirectory() as tmpdir:
898898
tmppath = pathlib.Path(tmpdir)
899899
pdf_path = tmppath / "figure.pdf"
900900
png_path = tmppath / "figure.png"
901-
self.print_pdf(pdf_path, *args, **kwargs)
901+
self.print_pdf(pdf_path, **kwargs)
902902
converter(pdf_path, png_path, dpi=self.figure.dpi)
903903
with png_path.open("rb") as orig, \
904904
cbook.open_file_cm(fname_or_fh, "wb") as dest:

lib/matplotlib/backends/backend_ps.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,15 +823,17 @@ class FigureCanvasPS(FigureCanvasBase):
823823
def get_default_filetype(self):
824824
return 'ps'
825825

826+
@_api.delete_parameter("3.5", "args")
826827
def print_ps(self, outfile, *args, **kwargs):
827-
return self._print_ps(outfile, 'ps', *args, **kwargs)
828+
return self._print_ps(outfile, 'ps', **kwargs)
828829

830+
@_api.delete_parameter("3.5", "args")
829831
def print_eps(self, outfile, *args, **kwargs):
830-
return self._print_ps(outfile, 'eps', *args, **kwargs)
832+
return self._print_ps(outfile, 'eps', **kwargs)
831833

832834
@_api.delete_parameter("3.4", "dpi")
833835
def _print_ps(
834-
self, outfile, format, *args,
836+
self, outfile, format, *,
835837
dpi=None, metadata=None, papertype=None, orientation='portrait',
836838
**kwargs):
837839

lib/matplotlib/backends/backend_svg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,7 @@ class FigureCanvasSVG(FigureCanvasBase):
12861286

12871287
fixed_dpi = 72
12881288

1289+
@_api.delete_parameter("3.5", "args")
12891290
def print_svg(self, filename, *args, **kwargs):
12901291
"""
12911292
Parameters
@@ -1337,6 +1338,7 @@ def print_svg(self, filename, *args, **kwargs):
13371338
if detach:
13381339
fh.detach()
13391340

1341+
@_api.delete_parameter("3.5", "args")
13401342
def print_svgz(self, filename, *args, **kwargs):
13411343
with cbook.open_file_cm(filename, "wb") as fh, \
13421344
gzip.GzipFile(mode='w', fileobj=fh) as gzipwriter:

lib/matplotlib/backends/backend_template.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
plt.savefig("figure.xyz")
3030
"""
3131

32+
from matplotlib import _api
3233
from matplotlib._pylab_helpers import Gcf
3334
from matplotlib.backend_bases import (
3435
FigureCanvasBase, FigureManagerBase, GraphicsContextBase, RendererBase)
@@ -209,6 +210,7 @@ def draw(self):
209210
# you should add it to the class-scope filetypes dictionary as follows:
210211
filetypes = {**FigureCanvasBase.filetypes, 'foo': 'My magic Foo format'}
211212

213+
@_api.delete_parameter("3.5", "args")
212214
def print_foo(self, filename, *args, **kwargs):
213215
"""
214216
Write out format foo.

0 commit comments

Comments
 (0)