question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Preferred docstring style

See original GitHub issue

pytest uses various docstring styles, which also leaks to the documentation, and I’m starting to develop an OCD from this!

I propose we use this style:

def func(arg: ArgType) -> Foo:
    """Do important stuff.

    More detailed info here, in separate paragraphs from the subject line.

    Use proper sentences -- start sentences with capital letters and end with periods.

    Can include annotated documentation:

    :param ArgType arg: an argument which determines stuff.
    :returns the result.
    :rtype Foo
    :raises ValueError
    """

After we agree on a style I’ll make a sweep over the code (possibly gradual) to update to it.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
aklajnertcommented, Jul 11, 2020

@nicoddemus

I agree with everything in the style except duplicating the type information when it we already have native type annotation, because Sphinx picks those up correctly.

From I remember in some previous PR sphinx doesn’t linkify the type in an annotation, but I’ll check again. Might not be worth the duplication even if it doesn’t.

IIRC I was using sphinx-autodoc-typehints extension to show the annotations correctly. Not sure if it will fit here, but might be worth checking.

0reactions
nicoddemuscommented, Jul 16, 2020
  1. I usually prefer imperative too, but don’t have strong feelings either.
  2. Capital letter and period. This is important when you need more than one phrase to explain a parameter.
  3. Also prefer the last one: easier to maintain.
  4. Agreed, same: aim for around 80 chars.
Read more comments on GitHub >

github_iconTop Results From Across the Web

What are the most common Python docstring formats?
There follows the main used formats for docstrings. - Epytext. Historically a javadoc like style was prevalent, so it was taken as a...
Read more >
3 Different Docstring Formats for Python | by Yash Salvi
3 Different Docstring Formats for Python · 1. Google Docstring · 2. NumPy Docstring · 3. Sphinx Docstring.
Read more >
Style guide — numpydoc v1.6.0rc1.dev0 Manual
The docstring consists of a number of sections separated by headings (except for the deprecation warning). Each heading should be underlined in hyphens,...
Read more >
Google Python Style Guide
Python uses docstrings to document code. A docstring is a string that is the first statement in a package, module, class or function....
Read more >
PEP 257 – Docstring Conventions
A docstring is a string literal that occurs as the first statement in a ... The preferred form for such a docstring would...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found