Skip to content
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

First pass of docstring additions. #1566

Merged
merged 1 commit into from
Jul 13, 2019
Merged

Conversation

nsnw
Copy link
Contributor

@nsnw nsnw commented Apr 24, 2019

Hey! With reference to #1565, I've started tidying up some of the docstrings in bot.py. I'm happy to help do others as well, but this is just to check that this is the kind of thing you're looking for. Feedback is obviously requested and will be gladly received!

@dgw dgw added this to the 7.0.0 milestone Apr 24, 2019
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

I'm surprised and happy to see a contribution toward #1565 so soon! Thank you for jumping in!

First feedback round! 🚀 The takeaways are:

  • More intersphinx links (see bot.write for an example of linking to the relevant glossary term for an argument's "type" when it's a concept, not a class or builtin)
    • Also intrasphinx (just normal references to functions, classes, constants… literally anything you can link to, inside or outside the Sopel codebase, should be linked)
  • Consistent whitespace (no blank lines between method docstring and method body)
  • Text wrapping
  • Parameter/body ordering

Those last two aren't addressed in any line notes, so I'll explain.

In the overhaul so far (just #1563 at this point), we have:

  1. Short method description (one line, ideally <80 chars)
  2. Parameters & types, with return value if applicable
  3. Longer description of the method, notes, etc.
  4. Version notes (added, changed, deprecated, what-have-you)

This PR adds the parameters and their types at the end of the docstring. Neither way is necessarily better—Sphinx puts the parameter list at the end in its output regardless of where it appears in the source—but we should be consistent. (This is where I wonder if @Exirel has any strong feelings either way. I like having the parameters above the detailed notes, but if there are any reasons to prefer one or the other besides "how the source code looks", I'm all ears eyes.)

Additionally, the overhaul so far has wrapped parameter descriptions to a hanging indent:

:param foobar: a very long parameter description that requires wrapping
               to fit within a reasonable line length

This PR uses the following, different, style:

:param foobar: a very long parameter description that requires wrapping
    to fit within a reasonable line length

I personally find the hanging-indent style to be easier for reading in source code form, but I acknowledge that it can significantly constrain the available text width for parameters with long names. (We seem to fall into using :type foobar: a lot, too, because of all the classnames referenced, which we want to link—and that can't be done inline as :param :class:`sopel.tools.Identifier` foobar:.)

I was also loosely restricting my updates in #1563 to fit all docstring text within the 80-column limit of PEP8, because we do want to unignore those linter rules at some point in The Distant Future (The Year Two-Thousand).

These are all just my personal opinions based on what I already worked on. All are open for discussion, as this initiative is still very new, and we definitely should figure out as much of our "style" as possible before too many PRs get merged and it becomes more and more tedious to change direction mid-stream. Reformatting stuff we already reformatted is not fun!

Fair warning: I'm also cutting my time working on this a bit short, because it's almost 3am already (holy crap, how?!) and I need to sleep! But I wanted to get as much as I could typed out so the discussion can at least percolate a bit—if not move forward without me for a while, between you and other contributors—until I can come back to it.

Thanks again for hopping to it (not an Easter pun, I swear…) so soon after I opened that tracking issue! 🙌 🖖

sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
@dgw
Copy link
Member

dgw commented Apr 24, 2019

I had all but given up trying to figure out how to link re.Pattern as an example, so I left it out of my review.

But! This worked when I tweaked the current PR state locally and built the HTML docs:

    def register_url_callback(self, pattern, callback):
        """Register a ``callback`` for URLs matching the regex ``pattern``

        :param pattern: compiled regex pattern to register
        :type pattern: :ref:`re.Pattern <python:re-objects>`
        :param function callback: callable object to handle matching URLs
[... etc ...]

pattern's type then links to https://docs.python.org/3/library/re.html#re-objects by doing this, which is precisely the section needed. Why it's not linkable as #re.Pattern despite describing what appear to be objects of that type, I don't know. But this is a solution to the "More intersphinx links" point I requested.

@nsnw
Copy link
Contributor Author

nsnw commented Apr 24, 2019

Thanks for the feedback! I'll make a start on incorporating the feedback :-D

@nsnw
Copy link
Contributor Author

nsnw commented Apr 25, 2019

I've incorporated the feedback, and:-

  • docstrings are now limited to 80 characters wide
  • moved parameter definitions to the top of the docstrings (under the initial one-line description)
  • switching to hanging indentation for line-wrapped parameter definitions
  • added glossary links for concepts (using :term: as suggested)
  • removed blank newlines between docstring definitions and method bodies

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

Round two! Not a whole lot here, honestly. The indentation fixes and added links look 👌!

After this round is addressed, I'll pull the PR branch down and test-render it before (hopefully) final approval.

sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

OK, this time I really think I caught everything. Honestly, I probably still missed an inconsistency or two, but let me know if you're tired of the back-and-forth. 😄

I drove away a contributor last year by being too demanding, and I really want to avoid doing that again… 😞

sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
@nsnw
Copy link
Contributor Author

nsnw commented Apr 29, 2019

You're not being too demanding!

I've pushed the latest version. I've added the "to a user or channel" wording to all the ones that it makes for now. I personally can't decide which is better - with or without it - but I'll leave it to you to decide.

sopel/bot.py Outdated Show resolved Hide resolved
@dgw
Copy link
Member

dgw commented Apr 29, 2019

You're not being too demanding!

That's a relief! All the same, I thank you for putting up with the lengthy iteration process. 😸

I've added the "to a user or channel" wording to all the ones that it makes for now. I personally can't decide which is better - with or without it - but I'll leave it to you to decide.

Obviously, I choose to keep "to a user or channel" in places where it makes sense to include, but without the second "a" that (to me) makes the phrase slightly redundant.

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

Phew. This project so far has taught me why the documentation I've seen even in large, well-established projects can be so inconsistent. It's exhausting making sure everything is "perfect", and time-consuming!

It appears that I was very wrong in my previous review earlier tonight, sadly. I didn't catch anywhere close to everything. Therefore, even though I think this is the real last batch of fixes, I'm not going to say it—maybe if I don't assert that this is the end, I'll avoid jinxing it?

sopel/bot.py Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Show resolved Hide resolved
sopel/bot.py Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
@nsnw
Copy link
Contributor Author

nsnw commented May 5, 2019

I am still working on this! I've just been busy with work. Hoping to get this finished in the next few days.

@Exirel
Copy link
Contributor

Exirel commented May 8, 2019

Just a quick note to say: I love it! 👍
Also you'll have to rebase and resolve some conflict. And the more PR get merged, the more conflicts you'll have to fix.

@nsnw
Copy link
Contributor Author

nsnw commented May 30, 2019

Ok! Sorry for the delay - currently in the process of buying a house so things got in the way -_-

In the latest commit I've implemented the suggestions, including:-

  • switching single backticks to double backticks where appropriate - a scan of the generated HTML after this doesn't show any instances of <cite>/</cite>
  • added periods at the end of sentences - I think I've now caught them all
  • removed 2 instances of double spaces after a period

There were a couple of other bits I've found as well that I fixed.

@nsnw
Copy link
Contributor Author

nsnw commented May 30, 2019

I've merged in the latest changes from master, so this should be current against those.

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

I've run out of nitpicks!

Besides the last few tweaks suggested, I would request that you clean up the branch commit history per our contribution guidelines. There's no "one right way" to do this, but in general we like to avoid merging fixup commits without squashing them first. This PR does not need to be squashed all the way down to a single commit, but there are a lot of "fix" messages in the log right now. :)

Apologies for the delay, @nsnw; I was traveling for the last three weeks with very little free time for this (or any) GitHub project.

sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
@nsnw
Copy link
Contributor Author

nsnw commented Jul 12, 2019

Excellent! Been a bit busy (getting married in a few weeks!) but I'll make the tweaks above and tidy up the PR. Once that's done I'll start looking at others :-)

@Exirel
Copy link
Contributor

Exirel commented Jul 12, 2019

@nsnw that's lovely! 😍

@nsnw nsnw force-pushed the doc-improvements branch from 2ff3f06 to d537b39 Compare July 12, 2019 17:42
@nsnw nsnw force-pushed the doc-improvements branch from d537b39 to 320f9d2 Compare July 12, 2019 17:44
@nsnw
Copy link
Contributor Author

nsnw commented Jul 12, 2019

Okay - I believe I've squashed everything down to a single commit now. I have to admit that squashing and rebasing is not my strong point so if I've butchered it I apoplogise!

Copy link
Contributor

@Exirel Exirel left a comment

Choose a reason for hiding this comment

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

🚢 (and don't wait too long because merge conflict can come fast with such changes!)

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

Great, let's :shipit:.

@nsnw Congrats on the merge (momentarily)—but also, congratulations on the upcoming wedding!

@dgw dgw merged commit 20af487 into sopel-irc:master Jul 13, 2019
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.

3 participants