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

Make black remove leading and trailing spaces from one-line docstrings: fixes #1738 #1812 #1740

Merged
merged 17 commits into from
Apr 22, 2021
Merged

Make black remove leading and trailing spaces from one-line docstrings: fixes #1738 #1812 #1740

merged 17 commits into from
Apr 22, 2021

Conversation

MarkCBell
Copy link
Contributor

@MarkCBell MarkCBell commented Oct 2, 2020

Resolves #1738 Black removes leading and trailing spaces in multiline docstrings but fails to remove them from one-line docstrings

@MarkCBell
Copy link
Contributor Author

It appears that the primer check are checking how black affects a number of different projects. Since this changes how single line docstrings are processed a number of these now change.

@MarkCBell MarkCBell changed the title Now strip leading and trailing whitespace from single line docstrings. Black removes leading and trailing spaces in multiline docstrings but fails to remove them from one-line docstrings Oct 3, 2020
@MarkCBell MarkCBell changed the title Black removes leading and trailing spaces in multiline docstrings but fails to remove them from one-line docstrings Black removes leading and trailing spaces in multiline docstrings but fails to remove them from one-line docstrings #1738 Oct 3, 2020
@MarkCBell MarkCBell changed the title Black removes leading and trailing spaces in multiline docstrings but fails to remove them from one-line docstrings #1738 Black removes leading and trailing spaces in multiline docstrings but fails to remove them from one-line docstrings: fixes #1738 Oct 3, 2020
@MarkCBell MarkCBell changed the title Black removes leading and trailing spaces in multiline docstrings but fails to remove them from one-line docstrings: fixes #1738 Make black remove leading and trailing spaces from one-line docstrings: fixes #1738 Oct 3, 2020
@felix-hilden
Copy link
Collaborator

I've seen the Black team cautious about other than formatting changes in the source code elsewhere, but given that such processing is already done with other docstrings, this seems warranted. Also, the code is simple enough.

The test run logs seem to have timed out. I don't know if they can be rerun manually, or does the branch need to be updated, but having fresh results would be nice. Also there are conflicts with the current master, so fixing that would also update the branch and let you run the tests once more!

I'm not a maintainer though, so you'll sadly have to wait for someone else. Hopefully someone is able to do a quick review!

@ichard26
Copy link
Collaborator

I think the main issue is that it's not clear how we want to handle docstring formating still. IRCC the current behaviour was a mistake added by a somewhat unrelated feature addition, so we might just rollback to the previous formatting, IDK and I haven't looked into it.

@felix-hilden
Copy link
Collaborator

Oh, I see! Thanks for the information!

Rephrasing required while PR checks for CHANGES.md and Lint can contradict each other. Raised as issue 2070.
@MarkCBell
Copy link
Contributor Author

MarkCBell commented Mar 27, 2021

Also there are conflicts with the current master, so fixing that would also update the branch and let you run the tests once more!

I have resolved the conflicts (and opened #2072 to deal with problems in the PR checking process).

As expected, the issues about the Primer checks into how black affects a number of different projects still remain.

Copy link
Collaborator

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Looks good to me except for a suggested improvement in wording

CHANGES.md Outdated Show resolved Hide resolved
@JelleZijlstra
Copy link
Collaborator

IRCC the current behaviour was a mistake added by a somewhat unrelated feature addition

In fact it was added on purpose in #1053.

@JelleZijlstra
Copy link
Collaborator

Also (sorry for the stream of consciousness), you'll have to update the black-primer configuration to reflect any additional projects with expected changes, assuming the changes all look right.

I checked out a few of them and did notice one special case:

 class DummyContext:
-    """ """
+    """"""

I don't really know why they're doing this, but it looks a lot weirder with no space in the middle. Maybe we should avoid completely emptying a docstring that consists only of spaces, instead replace it with a single space? I don't feel strongly about this; if others here prefer the completely empty string we can just keep things as is.

@ichard26
Copy link
Collaborator

Sorry for not submitting my review earlier, to be honest, I was extremely confused by the docstring handling Black has right now. I thought Black modified docstrings much more than what is actually true. I really don't care about the indention or space cleanup Black does, the only thing that isn't immediately clear to me is the behaviour for docstring quotes, in particular the behaviour described in #1635.

Putting this file through Black on master d960d5d:

def test():
    """This is one possibility.

    Very important stuff here.
    """


def test2():
    """This is another one possibility.

    Very important stuff here."""


def test3():
    """
    This is another one possibility.

    Very important stuff here.
    """


def test4():
    """
    What about this?
    """


def test5():
    """What about this?

    Some people also like to have an empty line at the end of the doc string.

    """


def test6():
    """Single line docstrings also exist."""


def test7():
    """
    Some people like them like this.
    """


def test8():
    """Or like this.
    """


def test9():
    """
    Or even like this."""


def test10():
    """Plus this.....

    style"""

returns this diff:

--- test.py	2021-04-11 22:07:57.113291 +0000
+++ test.py	2021-04-11 22:08:00.916690 +0000
@@ -42,12 +42,11 @@
     Some people like them like this.
     """
 
 
 def test8():
-    """Or like this.
-    """
+    """Or like this."""
 
 
 def test9():
     """
     Or even like this."""

which rubs me in the wrong way, either Black becomes more consistent with the "if can be collapsed into a single line docstring, it will" rule (i.e. collapse test6-10 not just test8), OR just remove this handling to let the user have full choice with where the quotes go.

P.S. perhaps we could document the handling (indention fixing, whitespace removal, etc.) Black has so it's easy to find and clear?

Copy link
Collaborator

@ichard26 ichard26 left a comment

Choose a reason for hiding this comment

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

Please resolve the merge conflict and other than this looks good to me (edit: also please resolve Jelle's comments!). Thanks!

Regarding """""" vs """ """, I'd go with """ """ too, but just like Jelle I don't feel strongly about this, so I'm open to some good ol' convincing by others :)

@ichard26
Copy link
Collaborator

PS. I'm pretty sure #1812 can also be closed by this PR. Can you link in the description so we don't forget to close it?

dpgeorge pushed a commit to micropython/micropython that referenced this pull request Apr 27, 2021
Since version 21.4b0, Black now processes one-line docstrings by stripping
leading and trailing spaces, and adding a padding space when needed to
break up """"; see psf/black#1740

This commit makes the Python code in this repository conform to this rule.
mdolin pushed a commit to xlab-steampunk/sensu-go-python that referenced this pull request Apr 30, 2021
Update on the usage of the Black version, which
resolves the problem of removing leading and trailing
spaces in one-line docstrings.
psf/black#1740
tadeboro pushed a commit to sensu/sensu-go-python that referenced this pull request May 2, 2021
Update on the usage of the Black version, which
resolves the problem of removing leading and trailing
spaces in one-line docstrings.
psf/black#1740
pfalcon pushed a commit to pfalcon/pycopy that referenced this pull request Jun 1, 2021
Since version 21.4b0, Black now processes one-line docstrings by stripping
leading and trailing spaces, and adding a padding space when needed to
break up """"; see psf/black#1740

This commit makes the Python code in this repository conform to this rule.
pfalcon pushed a commit to pfalcon/pycopy that referenced this pull request Jun 2, 2021
Since version 21.4b0, Black now processes one-line docstrings by stripping
leading and trailing spaces, and adding a padding space when needed to
break up """"; see psf/black#1740

This commit makes the Python code in this repository conform to this rule.
pfalcon pushed a commit to pfalcon/pycopy that referenced this pull request Jun 5, 2021
Since version 21.4b0, Black now processes one-line docstrings by stripping
leading and trailing spaces, and adding a padding space when needed to
break up """"; see psf/black#1740

This commit makes the Python code in this repository conform to this rule.
pfalcon pushed a commit to pfalcon/pycopy that referenced this pull request Jun 6, 2021
Since version 21.4b0, Black now processes one-line docstrings by stripping
leading and trailing spaces, and adding a padding space when needed to
break up """"; see psf/black#1740

This commit makes the Python code in this repository conform to this rule.
pfalcon pushed a commit to pfalcon/pycopy that referenced this pull request Jun 7, 2021
Since version 21.4b0, Black now processes one-line docstrings by stripping
leading and trailing spaces, and adding a padding space when needed to
break up """"; see psf/black#1740

This commit makes the Python code in this repository conform to this rule.
pfalcon pushed a commit to pfalcon/pycopy that referenced this pull request Jun 7, 2021
Since version 21.4b0, Black now processes one-line docstrings by stripping
leading and trailing spaces, and adding a padding space when needed to
break up """"; see psf/black#1740

This commit makes the Python code in this repository conform to this rule.
pfalcon pushed a commit to pfalcon/pycopy that referenced this pull request Jun 8, 2021
Since version 21.4b0, Black now processes one-line docstrings by stripping
leading and trailing spaces, and adding a padding space when needed to
break up """"; see psf/black#1740

This commit makes the Python code in this repository conform to this rule.
pfalcon pushed a commit to pfalcon/pycopy that referenced this pull request Jun 9, 2021
Since version 21.4b0, Black now processes one-line docstrings by stripping
leading and trailing spaces, and adding a padding space when needed to
break up """"; see psf/black#1740

This commit makes the Python code in this repository conform to this rule.
pfalcon pushed a commit to pfalcon/pycopy that referenced this pull request Jun 11, 2021
Since version 21.4b0, Black now processes one-line docstrings by stripping
leading and trailing spaces, and adding a padding space when needed to
break up """"; see psf/black#1740

This commit makes the Python code in this repository conform to this rule.
pfalcon pushed a commit to pfalcon/pycopy that referenced this pull request Jun 12, 2021
Since version 21.4b0, Black now processes one-line docstrings by stripping
leading and trailing spaces, and adding a padding space when needed to
break up """"; see psf/black#1740

This commit makes the Python code in this repository conform to this rule.
ksekimoto pushed a commit to ksekimoto/micropython that referenced this pull request Jul 16, 2021
Since version 21.4b0, Black now processes one-line docstrings by stripping
leading and trailing spaces, and adding a padding space when needed to
break up """"; see psf/black#1740

This commit makes the Python code in this repository conform to this rule.
GeoWill added a commit to DemocracyClub/EveryElection that referenced this pull request Oct 27, 2021
In release 21.4b0: psf/black#1740
GeoWill added a commit to DemocracyClub/EveryElection that referenced this pull request Oct 27, 2021
In release 21.4b0: psf/black#1740
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Nov 13, 2021
…driver-reviewers,whimboo,gerard-majax

This changed with this:
psf/black#1740

Differential Revision: https://phabricator.services.mozilla.com/D130965
jamienicol pushed a commit to jamienicol/gecko that referenced this pull request Nov 15, 2021
…driver-reviewers,whimboo,gerard-majax

This changed with this:
psf/black#1740

Differential Revision: https://phabricator.services.mozilla.com/D130965
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Nov 23, 2021
…l,webdriver-reviewers,perftest-reviewers,whimboo,gerard-majax,alexandru.irimovici

This changed with this:
psf/black#1740

Depends on D130964

Differential Revision: https://phabricator.services.mozilla.com/D130965
jamienicol pushed a commit to jamienicol/gecko that referenced this pull request Nov 23, 2021
…l,webdriver-reviewers,perftest-reviewers,whimboo,gerard-majax,alexandru.irimovici

This changed with this:
psf/black#1740

Depends on D130964

Differential Revision: https://phabricator.services.mozilla.com/D130965
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants