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

""" Leading summary whitespace (as in this issue title).""" #39

Closed
olibre opened this issue Aug 20, 2019 · 8 comments
Closed

""" Leading summary whitespace (as in this issue title).""" #39

olibre opened this issue Aug 20, 2019 · 8 comments
Labels
C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) P: enhancement Feature that is outside the scope of PEP 257

Comments

@olibre
Copy link

olibre commented Aug 20, 2019

For better readability, some people prefer inserting a space between the triple quotes """ and the summary text:

def is_ascii(text):
    """ Checks if contains only ASCII characters."""
    return all(ord(letter) < 128 for letter in text)

The leading whitespace:

       🡇
    """ Checks if contains only ASCII characters."""

Without that whitespace:

    """Checks if contains only ASCII characters."""

We may add an option --leading-summary-space or --pre-summary-space or --space-before-summary or --space-after-triple-quotes... What option name do you prefer?

Attention, this option has no effect on multi-lines docstring when --pre-summary-newline is used.

Thanks

@olibre olibre changed the title """ Whitespace before summary text (as in this issue title) """ Leading summary whitespace (as in this issue title).""" Aug 21, 2019
@ndevenish
Copy link

--pre-summary-space matches the --pre-summary-newline option for naming, so would probably be the least confusing.

@myint myint added P: enhancement Feature that is outside the scope of PEP 257 help wanted labels Dec 23, 2019
@alecmerdler
Copy link
Contributor

@ndevenish Made a pull request adding this option. Mind trying it out?

@merwok
Copy link

merwok commented Jan 21, 2020

😮 I have seen extra spaces around a one-line docstring, or extra leading space on the first line of a multiline docstring, but didn’t know there was a style of one-line docstring with leading space but no trailing space.

@thejcannon
Copy link

thejcannon commented Mar 7, 2022

Note that black inserts the leading whitespace. Therefore if you use both black and docformatter you'll be in formatting limbo.

See psf/black#2912

@thejcannon
Copy link

Also worth pointing out https://docs.python.org/3/library/inspect.html#inspect.cleandoc strips this, so it should have no semantic difference (help docs do not have the whitespace).

@thejcannon
Copy link

Last comment, black only inserts the leading space if the first character is the quote, so it's obvious there's an extra quote. Otherwise there isn't a leading space.

E.g.

# Adds leading space
""" "I'm quoted"."""
# But also doesn't
"""I'm not quoted."""

So applying the space everywhere would still land you in limbo.

@weibullguy
Copy link
Member

@thejcannon thanks for pointing this out.

PR #46 is submitted to add the leading space. Once that PR is merged, using the --pre-summary-space option will maintain the black-inserted space. For those who prefer the non-space formatting they would need to run black first, then docformatter. I've asked the #46 pull requester to address this interaction in the README.

@weibullguy
Copy link
Member

Closed by #46

@weibullguy weibullguy added C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) and removed help wanted labels Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) P: enhancement Feature that is outside the scope of PEP 257
Projects
None yet
Development

No branches or pull requests

7 participants