-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
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. |
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! |
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. |
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.
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. |
There was a problem hiding this 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
In fact it was added on purpose in #1053. |
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:
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. |
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? |
There was a problem hiding this 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 :)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
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? |
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.
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
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
In release 21.4b0: psf/black#1740
In release 21.4b0: psf/black#1740
…driver-reviewers,whimboo,gerard-majax This changed with this: psf/black#1740 Differential Revision: https://phabricator.services.mozilla.com/D130965
…driver-reviewers,whimboo,gerard-majax This changed with this: psf/black#1740 Differential Revision: https://phabricator.services.mozilla.com/D130965
…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
…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
Resolves #1738 Black removes leading and trailing spaces in multiline docstrings but fails to remove them from one-line docstrings