Skip to content

Deprecate unused \*args to print_<foo>. #19487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/deprecations/19487-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Unused positional parameters to ``print_<fmt>`` methods are deprecated
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

None of the ``print_<fmt>`` methods implemented by canvas subclasses used
positional arguments other that the first (the output filename or file-like),
so these extra parameters are deprecated.
3 changes: 3 additions & 0 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ def buffer_rgba(self):
return self.renderer.buffer_rgba()

@_check_savefig_extra_args
@_api.delete_parameter("3.5", "args")
def print_raw(self, filename_or_obj, *args):
FigureCanvasAgg.draw(self)
renderer = self.get_renderer()
Expand All @@ -457,6 +458,7 @@ def print_raw(self, filename_or_obj, *args):
print_rgba = print_raw

@_check_savefig_extra_args
@_api.delete_parameter("3.5", "args")
def print_png(self, filename_or_obj, *args,
metadata=None, pil_kwargs=None):
"""
Expand Down Expand Up @@ -528,6 +530,7 @@ def print_to_buffer(self):
alternative="pil_kwargs={'optimize': ...}")
@_api.delete_parameter("3.3", "progressive",
alternative="pil_kwargs={'progressive': ...}")
@_api.delete_parameter("3.5", "args")
def print_jpg(self, filename_or_obj, *args, pil_kwargs=None, **kwargs):
"""
Write the figure to a JPEG file.
Expand Down
5 changes: 0 additions & 5 deletions lib/matplotlib/backends/backend_gtk3agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ def draw(self):
backend_agg.FigureCanvasAgg.draw(self)
super().draw()

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


class FigureManagerGTK3Agg(backend_gtk3.FigureManagerGTK3):
pass
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,17 +843,17 @@ def _print_pgf_to_fh(self, fh, *, bbox_inches_restore=None):
writeln(fh, r"\makeatother")
writeln(fh, r"\endgroup")

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

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

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

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

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

def print_png(self, fname_or_fh, *args, **kwargs):
def print_png(self, fname_or_fh, **kwargs):
"""Use LaTeX to compile a pgf figure to pdf and convert it to png."""
converter = make_pdf_to_png_converter()
with TemporaryDirectory() as tmpdir:
tmppath = pathlib.Path(tmpdir)
pdf_path = tmppath / "figure.pdf"
png_path = tmppath / "figure.png"
self.print_pdf(pdf_path, *args, **kwargs)
self.print_pdf(pdf_path, **kwargs)
converter(pdf_path, png_path, dpi=self.figure.dpi)
with png_path.open("rb") as orig, \
cbook.open_file_cm(fname_or_fh, "wb") as dest:
Expand Down
8 changes: 5 additions & 3 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,15 +823,17 @@ class FigureCanvasPS(FigureCanvasBase):
def get_default_filetype(self):
return 'ps'

@_api.delete_parameter("3.5", "args")
def print_ps(self, outfile, *args, **kwargs):
return self._print_ps(outfile, 'ps', *args, **kwargs)
return self._print_ps(outfile, 'ps', **kwargs)

@_api.delete_parameter("3.5", "args")
def print_eps(self, outfile, *args, **kwargs):
return self._print_ps(outfile, 'eps', *args, **kwargs)
return self._print_ps(outfile, 'eps', **kwargs)

@_api.delete_parameter("3.4", "dpi")
def _print_ps(
self, outfile, format, *args,
self, outfile, format, *,
dpi=None, metadata=None, papertype=None, orientation='portrait',
**kwargs):

Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,7 @@ class FigureCanvasSVG(FigureCanvasBase):

fixed_dpi = 72

@_api.delete_parameter("3.5", "args")
def print_svg(self, filename, *args, **kwargs):
"""
Parameters
Expand Down Expand Up @@ -1337,6 +1338,7 @@ def print_svg(self, filename, *args, **kwargs):
if detach:
fh.detach()

@_api.delete_parameter("3.5", "args")
def print_svgz(self, filename, *args, **kwargs):
with cbook.open_file_cm(filename, "wb") as fh, \
gzip.GzipFile(mode='w', fileobj=fh) as gzipwriter:
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/backends/backend_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
plt.savefig("figure.xyz")
"""

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

@_api.delete_parameter("3.5", "args")
def print_foo(self, filename, *args, **kwargs):
"""
Write out format foo.
Expand Down