Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Move unrendered docstrings to private attributes. #10233

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
Jan 15, 2018

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jan 11, 2018

Note that using @property to deprecate the attributes doesn't really
help as we'd want something that also returns the string value when
accessed from a class rather than from an instance; while it is
technically possible to write such a descriptor that seems a bit
overkill...

Closes #5873 and #9642.

Note that git thinks that the diff on QuadContourSet is code being moved around but actually I moved the docstring around, it's just that the docstring is longer than the code...

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer force-pushed the hide-unrendered-docstrings branch 2 times, most recently from 76da091 to 6e5d5e4 Compare January 11, 2018 09:06
@tacaswell tacaswell added this to the v2.2 milestone Jan 12, 2018
@efiring
Copy link
Member

efiring commented Jan 12, 2018

Why are you moving that docstring?

@anntzer
Copy link
Contributor Author

anntzer commented Jan 12, 2018

to hide it from https://matplotlib.org/api/contour_api.html#matplotlib.contour.QuadContourSet.contour_doc (it's now a regular docstring instead of being (from sphinx's PoV) a module-global variable).

@efiring
Copy link
Member

efiring commented Jan 12, 2018

Could the problem also be solved with a moderate change in contour_api.rst, specifying the things to be documented rather than using auto-everything?
The reason I ask is that keeping very long docstrings as separate strings improves code readability by putting the method signature close to its body. That was the original rationale in this case, and I think it still applies.

@anntzer
Copy link
Contributor Author

anntzer commented Jan 12, 2018

It is not clear to me what you mean in this specific case. I'm basically changing

class QuadContourSet:
    """long docstring"""
    <long contents of the class>

    contour_doc = """some long docs"""

to

class QuadContourSet:
    """long docstring"""

    def __init__(self, *args, **kwargs):
	    """some long docs"""

    <long contents of the class>

which seems, if anything (regardless of sphinx), better?

@efiring
Copy link
Member

efiring commented Jan 12, 2018

I don't agree that it is better; having a very long docstring between the signature and the code makes it a little harder to work with the code.

@anntzer
Copy link
Contributor Author

anntzer commented Jan 12, 2018

Could probably turn it into a private variable instead.

@efiring
Copy link
Member

efiring commented Jan 12, 2018

Switching to a private variable sounds like a good idea--it hadn't occurred to me!

Note that using `@property` to deprecate the attributes doesn't really
help as we'd want something that also returns the string value when
accessed from a class rather than from an instance; while it is
technically possible to write such a descriptor that seems a bit
overkill...
@anntzer
Copy link
Contributor Author

anntzer commented Jan 12, 2018

edited accordingly

@anntzer anntzer force-pushed the hide-unrendered-docstrings branch from 6e5d5e4 to 5733e87 Compare January 12, 2018 20:24
@efiring
Copy link
Member

efiring commented Jan 13, 2018

Thank you for the change in strategy with the contour docstring. What about the tricontour doc string? @ianthomas23 might want to have a look.

Side question: In the docstrings themselves, why are the "::" instances mostly separate paragraphs, wasting two full lines, instead of being at the ends of the preceding paragraphs? My understanding from the reSt documentation is that if they are at the end of a paragraph and separated by a space, this is equivalent to having them in their own paragraphs.

@anntzer
Copy link
Contributor Author

anntzer commented Jan 13, 2018

The '::' can definitely be moved into the previous paragraph (and I agree it'll make things more compact). But that should go into a separate PR (to keep the diff of this one clear as a "move-only").

I believe quite strongly that the tricontour docstring belongs directly under the tricontour() signature (for the case of contour() I moved it back out as there wasn't really a place to put it anyways and I had to "invent" a pass-through constructor to host it, which was not particularly elegant either).

To be honest I believe that your point about docstrings taking too much place is better solved by having your favorite code editor fold the docstring, e.g. the screenshots at the bottom of https://chrisdown.name/2015/02/26/folding-python-docstrings-in-vim.html (I use https://github.com/tmhedberg/SimpylFold).

@jklymak jklymak merged commit 56976cf into matplotlib:master Jan 15, 2018
@anntzer anntzer deleted the hide-unrendered-docstrings branch January 15, 2018 19:06
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Useless Dvi dispatch docs in dvi_read api docs
5 participants