You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#2736 added a rule that preserves a blank line between attributes and methods. The implementation looks at the previous line instead of the previous statement, so it depends on the last statement in the (potentially arbitrarily nested) body if black inserts a blank line or not (code). #2783/#3564 fixes this for classes by always inserting a blank line, but this does not apply e.g. to function definitions. This affects e.g. typeshed, which uses if sys.version_info > (3, x): in stub files a lot.
I propose to change this to look at the type of the previous statement instead of the previous line.
## Summary
Fix all but one empty line differences with the black preview style in
typeshed. The remaining differences are breaking with type comments and
trailing commas in function definitions.
I compared the empty line differences with the preview mode of black
since stable has some oddities that would have been hard to replicate
(psf/black#3861). Additionally, it assumes the
style proposed in psf/black#3862.
An edge case that also surfaced with typeshed are newline before
trailing module comments.
**main**
| project | similarity index | total files | changed files |
|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1632 |
| django | 0.99966 | 2760 | 58 |
| transformers | 0.99930 | 2587 | 447 |
| twine | 1.00000 | 33 | 0 |
| **typeshed** | 0.99978 | 3496 | **2173** |
| warehouse | 0.99825 | 648 | 22 |
| zulip | 0.99950 | 1437 | 27 |
**PR**
| project | similarity index | total files | changed files |
|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1632 |
| django | 0.99966 | 2760 | 58 |
| transformers | 0.99930 | 2587 | 447 |
| twine | 1.00000 | 33 | 0 |
| **typeshed** | 0.99983 | 3496 | **18** |
| warehouse | 0.99825 | 648 | 22 |
| zulip | 0.99950 | 1437 | 27 |
Closes#6723
## Test Plan
The main driver was the typeshed diff. I added new test cases for all
kinds of possible empty line combinations in stub files, test cases for
newlines before trailing module comments.
---------
Co-authored-by: Micha Reiser <[email protected]>
#2736 added a rule that preserves a blank line between attributes and methods. The implementation looks at the previous line instead of the previous statement, so it depends on the last statement in the (potentially arbitrarily nested) body if black inserts a blank line or not (code). #2783/#3564 fixes this for classes by always inserting a blank line, but this does not apply e.g. to function definitions. This affects e.g. typeshed, which uses
if sys.version_info > (3, x):
in stub files a lot.I propose to change this to look at the type of the previous statement instead of the previous line.
Preview style
Desired style
(or a different set of blank line rules that don't inspect the previous function body anymore)
The text was updated successfully, but these errors were encountered: