Skip to content

Deprecate functions in backends #22797

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
Apr 7, 2022
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
12 changes: 12 additions & 0 deletions doc/api/next_api_changes/deprecations/22797-OG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Deprecation of helper functions in backends
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following functions are considered private and deprecated. Vendor the code
of the similarly named private functions if you rely on these functions.

* ``backend_pdf.fill``
* ``backend_ps.quote_ps_string``
* ``backend_svg.escape_attrib``
* ``backend_svg.escape_cdata``
* ``backend_svg.escape_comment``
* ``backend_svg.short_float_fmt``
13 changes: 9 additions & 4 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@
# * draw_quad_mesh


@_api.deprecated("3.6", alternative="Vendor the code")
def fill(strings, linelen=75):
return _fill(strings, linelen=linelen)


def _fill(strings, linelen=75):
"""
Make one string from sequence of strings, with whitespace in between.

Expand Down Expand Up @@ -292,15 +297,15 @@ def pdfRepr(obj):
# anything, so the caller must ensure that PDF names are
# represented as Name objects.
elif isinstance(obj, dict):
return fill([
return _fill([
b"<<",
*[Name(k).pdfRepr() + b" " + pdfRepr(v) for k, v in obj.items()],
b">>",
])

# Lists.
elif isinstance(obj, (list, tuple)):
return fill([b"[", *[pdfRepr(val) for val in obj], b"]"])
return _fill([b"[", *[pdfRepr(val) for val in obj], b"]"])

# The null keyword.
elif obj is None:
Expand All @@ -312,7 +317,7 @@ def pdfRepr(obj):

# A bounding box
elif isinstance(obj, BboxBase):
return fill([pdfRepr(val) for val in obj.bounds])
return _fill([pdfRepr(val) for val in obj.bounds])

else:
raise TypeError("Don't know a PDF representation for {} objects"
Expand Down Expand Up @@ -833,7 +838,7 @@ def write(self, data):
self.currentstream.write(data)

def output(self, *data):
self.write(fill([pdfRepr(x) for x in data]))
self.write(_fill([pdfRepr(x) for x in data]))
self.write(b'\n')

def beginStream(self, id, len, extra=None, png=None):
Expand Down
7 changes: 6 additions & 1 deletion lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ def _nums_to_str(*args):
return " ".join(f"{arg:1.3f}".rstrip("0").rstrip(".") for arg in args)


@_api.deprecated("3.6", alternative="Vendor the code")
def quote_ps_string(s):
return _quote_ps_string(s)


def _quote_ps_string(s):
"""
Quote dangerous characters of S for use in a PostScript string constant.
"""
Expand Down Expand Up @@ -738,7 +743,7 @@ def draw_gouraud_triangles(self, gc, points, colors, trans):
streamarr['flags'] = 0
streamarr['points'] = (flat_points - points_min) * factor
streamarr['colors'] = flat_colors[:, :3] * 255.0
stream = quote_ps_string(streamarr.tobytes())
stream = _quote_ps_string(streamarr.tobytes())

self._pswriter.write(f"""\
gsave
Expand Down
Loading