8000 List existing rcParams in rcParams docstring. by anntzer · Pull Request #18440 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

List existing rcParams in rcParams docstring. #18440

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
Sep 15, 2020
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
2 changes: 2 additions & 0 deletions doc/api/next_api_changes/behavior/18440-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docstring.Substitution now always dedents docstrings before string interpolation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 changes: 6 additions & 1 deletion lib/matplotlib/__init__.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@

# cbook must import matplotlib only within function
# definitions, so it is safe to import from it here.
from . import cbook, rcsetup
from . import cbook, docstring, rcsetup
from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
from matplotlib.cbook import mplDeprecation # deprecated
from matplotlib.rcsetup import validate_backend, cycler
Expand Down Expand Up @@ -635,13 +635,18 @@ def gen_candidates():
_all_deprecated = {*_deprecated_map, *_deprecated_ignore_map}


@docstring.Substitution("\n".join(map("- {}".format, rcsetup._validators)))
class RcParams(MutableMapping, dict):
"""
A dictionary object including validation.

Validating functions are defined and associated with rc parameters in
:mod:`matplotlib.rcsetup`.

The list of rcParams is:

%s

See Also
--------
:ref:`customizing-with-matplotlibrc-files`
Expand Down
58 changes: 30 additions & 28 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import copy
import logging
import textwrap

import numpy as np

Expand All @@ -53,35 +54,34 @@
_log = logging.getLogger(__name__)

_make_axes_param_doc = """
location : None or {'left', 'right', 'top', 'bottom'}
The location, relative to the parent axes, where the colorbar axes
is created. It also determines the *orientation* of the colorbar
(colorbars on the left and right are vertical, colorbars at the top
and bottom are horizontal). If None, the location will come from the
*orientation* if it is set (vertical colorbars on the right, horizontal
ones at the bottom), or default to 'right' if *orientation* is unset.
orientation : None or {'vertical', 'horizontal'}
The orientation of the colorbar. It is preferrable to set the
*location* of the colorbar, as that also determines the *orientation*;
passing incompatible values for *location* and *orientation* raises an
exception.
fraction : float, default: 0.15
Fraction of original axes to use for colorbar.
shrink : float, default: 1.0
Fraction by which to multiply the size of the colorbar.
aspect : float, default: 20
Ratio of long to short dimensions.
location : None or {'left', 'right', 'top', 'bottom'}
The location, relative to the parent axes, where the colorbar axes
is created. It also determines the *orientation* of the colorbar
(colorbars on the left and right are vertical, colorbars at the top
and bottom are horizontal). If None, the location will come from the
*orientation* if it is set (vertical colorbars on the right, horizontal
ones at the bottom), or default to 'right' if *orientation* is unset.
orientation : None or {'vertical', 'horizontal'}
The orientation of the colorbar. It is preferrable to set the *location*
of the colorbar, as that also determines the *orientation*; passing
incompatible values for *location* and *orientation* raises an exception.
fraction : float, default: 0.15
Fraction of original axes to use for colorbar.
shrink : float, default: 1.0
Fraction by which to multiply the size of the colorbar.
aspect : float, default: 20
Ratio of long to short dimensions.
"""
_make_axes_other_param_doc = """
pad : float, default: 0.05 if vertical, 0.15 if horizontal
Fraction of original axes between colorbar and new image axes.
anchor : (float, float), optional
The anchor point of the colorbar axes.
Defaults to (0.0, 0.5) if vertical; (0.5, 1.0) if horizontal.
panchor : (float, float), or *False*, optional
The anchor point of the colorbar parent axes. If *False*, the parent
axes' anchor will be unchanged.
Defaults to (1.0, 0.5) if vertical; (0.5, 0.0) if horizontal.
pad : float, default: 0.05 if vertical, 0.15 if horizontal
Fraction of original axes between colorbar and new image axes.
anchor : (float, float), optional
The anchor point of the colorbar axes.
Defaults to (0.0, 0.5) if vertical; (0.5, 1.0) if horizontal.
panchor : (float, float), or *False*, optional
The anchor point of the colorbar parent axes. If *False*, the parent
axes' anchor will be unchanged.
Defaults to (1.0, 0.5) if vertical; (0.5, 0.0) if horizontal.
"""

_colormap_kw_doc = """
Expand Down Expand Up @@ -214,7 +214,9 @@
However this has negative consequences in other circumstances, e.g. with
semi-transparent images (alpha < 1) and colorbar extensions; therefore, this
workaround is not used by default (see issue #1188).
""" % (_make_axes_param_doc, _make_axes_other_param_doc, _colormap_kw_doc))
""" % (textwrap.indent(_make_axes_param_doc, " "),
textwrap.indent(_make_axes_other_param_doc, " "),
_colormap_kw_doc))

# Deprecated since 3.4.
colorbar_doc = docstring.interpd.params["colorbar_doc"]
Expand Down
9 changes: 2 additions & 7 deletions lib/matplotlib/docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, *args, **kwargs):

def __call__(self, func):
if func.__doc__:
func.__doc__ %= self.params
func.__doc__ = inspect.cleandoc(func.__doc__) % self.params
return func

def update(self, *args, **kwargs):
Expand Down Expand Up @@ -72,9 +72,4 @@ def do_copy(target):
# Create a decorator that will house the various docstring snippets reused
# throughout Matplotlib.
interpd = Substitution()


def dedent_interpd(func):
"""Dedent *func*'s docstring, then interpolate it with ``interpd``."""
func.__doc__ = inspect.getdoc(func)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing getdoc to cleandoc doesn't have an effect?

8000

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one is called on the function, the other on the docstring?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getdoc says: "If the documentation string for an object is not provided and the object is a class, a method, a property or a descriptor, retrieve the documentation string from the inheritance hierarchy."

This inheritance doesn't apply to func.__doc__, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah indeed. On the other hand this was accidentally changed in the other direction in https://github.com/matplotlib/matplotlib/pull/13125/files#diff-0b973b83a5020c0418842e20e3ffc56cR115 so I guess I can always argue it's just going back to the old behavior :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something broke doc build though, though I'm not sure if it was this change specifically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, had a fix but forgot to push it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, I could not find any dedent_interpd on things that didn't have their own docstring.

return interpd(func)
dedent_interpd = interpd
0