-
Notifications
You must be signed in to change notification settings - Fork 55
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
Apply more granular changes by using # fmt: skip
#391
base: master
Are you sure you want to change the base?
Conversation
90bbf9d
to
1ae5448
Compare
@wkentaro indeed an interesting approach! In some test cases, the end result seems to be different, see build #1419. Do you think these are in fact improvements to old behavior instead of erroneous results due to a bug? What happens if the decorated lines become longer than 88 characters (or whatever is the configured Black margin)? I suppose that's ok because the comment instructs Black to ignore those lines and pass them through as such. Handling of empty lines seems to be asymmetrical in your implementation – decorating them is probably supposed to be special cased as well? What happens inside multi-line strings? What happens if I modify only some lines in a multi-line expression which doesn't already conform to Black formatting rules? For example if this is the old revision: call_func(first_arg=1,
second_arg = 2,
third_arg="three"
) and this is my new revision: call_func(first_arg=1,
second_arg = 2,
third_arg=3
) (so only the Would the whole function call still be reformatted by Black, or only the line I modified? According to your "After" example, the latter seems true. Which one would be desirable in your opinion? Could you approach replace the current Could we avoid the |
Yes, that's going to be ok.
In this case, Black ignores If we apply black with 2 times, it gives an expected result. UPDATE: if we don't change the line of multi-line string, Black raises error, so this needs to be fixed.
In this particular case, the Black won't reformat anything as there is going to be In my particular use case (a codebase of several people changing), I prefer the more conservative result since I can still reformat lines if I need it by
I just found an edge case by trying this. Without this is because
Yes, it seems possible by changing both |
32a4f22
to
8b44797
Compare
Your example had a concatenation of single-line strings split on multiple lines. What I meant was a triple-quoted multi-line string like e.g. """first line
second line
third line""" |
This seems to be a matter of preference. For me it's the opposite – I want the code base to be marching steadily towards complete Blackification, and if this sometimes means that a couple of neighboring unmodified statements are reformatted as well, that's a reasonable trade-off. This is what I attempted to solve in #221. I hoped to be able to extract Black's reformatted output in chunks corresponding to expressions which are parenthetically balanced and cover a sequence of complete lines of code. If it could also tell which original lines were reformatted, that set of information could replace the use of |
I'm postponing to consider this for 1.8.0. There are other features lined up for 1.7.0 and I prefer to not delay it further. |
Close #388
@akaihola What do you think of this solution? (NOTE: this won't work with nonstandard indentations)
Before
After
Limitations