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

Black should not change leading white space in doc strings #1698

Open
gar1t opened this issue Sep 12, 2020 · 3 comments
Open

Black should not change leading white space in doc strings #1698

gar1t opened this issue Sep 12, 2020 · 3 comments
Labels
F: docstrings How we format docstrings T: style What do we want Blackened code to look like?

Comments

@gar1t
Copy link

gar1t commented Sep 12, 2020

Black 20 is now changing this:

def p_col(p):
    """col : scalar_col
           | scalar_step_col
           | attr_col
           | flag_col
    """

to:

def p_col(p):
    """col : scalar_col
    | scalar_step_col
    | attr_col
    | flag_col
    """

Doc strings can be used for formatted text including, well, anything you want. In this case the doc strings are used by PLY to define a parsing grammar. This issue will effect anything that uses leading white space such as Markdown. It's bad form to start mucking with prose. You have no idea what's in there. White space that starts and ends the comment is fair game but not the content in between.

@gar1t gar1t added the T: style What do we want Blackened code to look like? label Sep 12, 2020
gar1t pushed a commit to guildai/guildai that referenced this issue Sep 12, 2020
Protesting reformatting of parser grammar (see
psf/black#1698). Rest is fine.
@C0DK
Copy link
Contributor

C0DK commented Oct 5, 2020

I don't agree. If you want formatting like that, i would advice on using a dot or backslash on the "zeroth" space, so it doesn't indent

@gar1t
Copy link
Author

gar1t commented Oct 5, 2020

Can you or someone offer an explanation of why Black disregards PEP 257?

Docstring processing tools will strip a uniform amount of indentation from the second and further lines of the docstring, equal to the minimum indentation of all non-blank lines after the first line. Any indentation in the first line of the docstring (i.e., up to the first newline) is insignificant and removed. Relative indentation of later lines in the docstring is retained. Blank lines should be removed from the beginning and end of the docstring.

Emphasis is mine.

In the case of my example, the doc string is a grammar. I don't have the luxury of making up a syntax to workaround Black's decision to reformat the doc string. Similarly, someone using reStructuredText, a standard use of doc string, does not have the luxury of making up a new syntax based on your workaround suggestion. Leading white space is meaningful in both cases. It's meaningful for Markdown. Black is not only violating Python standards here it's breaking common use of doc string.

Do you disagree with that?

@C0DK
Copy link
Contributor

C0DK commented Oct 6, 2020

I regres. You are correct.

@JelleZijlstra JelleZijlstra added the F: strings Related to our handling of strings label May 30, 2021
@felix-hilden felix-hilden added F: docstrings How we format docstrings and removed F: strings Related to our handling of strings labels Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: docstrings How we format docstrings T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

4 participants