Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
story645 wants to merge2 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromstory645:interp-doc

Conversation

story645
Copy link
Member

@story645story645 commentedAug 22, 2024
edited
Loading

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 commentedSep 9, 2024
edited
Loading

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. (since916f4ff)interpd also always corrects indentation. Thereforededent_interpd andinterpd are equivalent and we should removededent_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 isargs or kwargs (i.e. a tuple or a dict). This is ok for formatting (inspect.cleandoc(func.__doc__) % self.params). ButSubstitution has anupdate() method, which only works whenparams 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 commentedSep 10, 2024
edited
Loading

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 ithttps://en.wikipedia.org/wiki/String_interpolation (though generally only applying immediately to literals, I think, it could be argued as similar enough.)

story645 reacted with thumbs up emoji

@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.

rcomer reacted with thumbs up emoji

@story645
Copy link
MemberAuthor

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

timhoffm reacted with thumbs up emoji

@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.

story645 reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
Documentation: devdocsfiles in doc/devel
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@story645@timhoffm@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp