Skip to content

Navigation Menu

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

DOC: document how to created interpolated stubs #28746

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
Loading
from

Conversation

story645
Copy link
Member

@story645 story645 commented Aug 22, 2024

PR summary

Inspired by the colorizer and InsetArtist PRs that are both adding new objects that get used in a few places/forwarded to, I added a section to the doc docs documenting how to add _docstring.interpd docs.

Also deleted note on how we're still debating whether we want to use this functionality because that note was added in 2017 on how this functionality is up for debate b/c either:

  • no decision means decision was to keep status quo and then we should document how to use this nice reusable doc tool
  • we don't want to use this and then we should document "we don't use this, here's what you should do instead"

I didn't document how to use the kwdoc functionality b/c I don't understand it enough to:

class _ArtistPropertiesSubstitution(Substitution):
"""
A `.Substitution` with two additional features:
- Substitutions of the form ``%(classname:kwdoc)s`` (ending with the
literal ":kwdoc" suffix) trigger lookup of an Artist subclass with the
given *classname*, and are substituted with the `.kwdoc` of that class.
- Decorating a class triggers substitution both on the class docstring and
on the class' ``__init__`` docstring (which is a commonly required
pattern for Artist subclasses).
"""

PR checklist

@timhoffm
Copy link
Member

timhoffm commented Sep 9, 2024

Admittedly, I also don't have a full overview on our substitution mechanims (but possibly that's part of the problem here). I have the feeling that the description here only targets part of our machinery and it is still not clear what exactly we have and for which
cases it should be used.

We have

  • _docstring.copy: A decorator to copy a docstring from another function.
    Assumed use cases::
    • Re-expose the same docstring on a different function (used for pyplot wrappers)
    • copy "docstring templates" (see. Substitution)
  • Substitution: A decorator for %-substition of docstrings.
    Assumed use cases:
    • Inject runtime information into docstrings (e.g. RcParams)
    • Inject the same code into multiple docstrings to prevent repetition (e.g. _RECTANGLESELECTOR_PARAMETERS_DOCSTRING)
    • Allow variations of a reused docstring (e.g. through @_docstring.copy)
  • _ArtistPropertiesSubstitution (instantiated as _docsting.dedent_interpd / _docstring.interpd)
    Assumed use cases:
    • Register for named placeholders, e.g. %(cmap_doc)s - add entries via @_docstring.interpd.update()`
    • Use as decorator for
      • Resolving the registered named placeholders in associated docstrings
      • Automatic resolution of %(classname:kwdoc)s

Notes:

  1. (since 916f4ff) interpd also always corrects indentation. Therefore dedent_interpd and interpd are equivalent and we should remove dedent_interpd.
  2. I've an issue with naming. "Interpolation" seems like a slang term. What we do is inject content / substitute placeholders / technically perform string formatting for a predefined set of names. I believe we should make this more clear in our naming.
  3. There are some quirks in the class design, e.g. Substitution.params is args or kwargs (i.e. a tuple or a dict). This is ok for formatting (inspect.cleandoc(func.__doc__) % self.params). But Substitution has an update() method, which only works when params is a dict.

I believe we first have to clean up and sort out what we actually want to do with these helpers before we can cleanly document their usage.

@QuLogic
Copy link
Member

QuLogic commented Sep 10, 2024

I've an issue with naming. "Interpolation" seems like a slang term. What we do is inject content / substitute placeholders / technically perform string formatting for a predefined set of names. I believe we should make this more clear in our naming.

It is a defined term for it https://en.wikipedia.org/wiki/String_interpolation (though generally only applying immediately to literals, I think, it could be argued as similar enough.)

@timhoffm
Copy link
Member

If we want to cling to "interpolation", we should use the full technical "string interpolation" (or "docstring interpolation" if you want). "interpolation" by itself is much more associated with mathematics, which would be confusing.

@story645
Copy link
Member Author

I was gonna just change it up to something like "Create reusable docstrings" - focus on purpose rather than mechanism 🤷‍♀️

@timhoffm
Copy link
Member

I like "Reuse docstrings". It has more focus on the act of reusing compared to the creation.

This section could contain the existing "Inherit docstrings" as a subsection. It should eventually mention all _docstring methods:

But as you say, structure by purpose rather than mechanics. I believe the "Assumed use cases" from #28746 (comment) could be a guideline for purposes. I think we currently do:

  • Inject runtime information into docstrings: _docstring.format
  • Use the same (template) docstring for multiple functions: _docstring.copy. Variations can be added on top via _docstring.format
  • Use the same pre-defined fragment inside multiple docstrings: _docstring.interpd

That said, I'm not quite clear whether we need both _docstring.format and _docstring.interpd. The difference being that format gives the content to insert explicitly, whereas interpd takes it by name from a registry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation: devdocs files in doc/devel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.