-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Reconsider formatting that was changed by #762 #781
Comments
I think this might also be a bug, because it's now producing some lines that are longer than 88 characters. 😞 An examples from one of our codebases: Beforeclass Foo:
def meth(self):
allow_partial_registration = (
self.allow_partial_registration_completion
and state.get("allow_partial_registration")
) Afterclass Foo:
def meth(self):
# the next line is 94 characters!
allow_partial_registration = self.allow_partial_registration_completion and state.get(
"allow_partial_registration"
) I also see it with several tests, where #762 changed assert (
something_long
== something_else_very_long.method_call(x)
) into # in the actual code base, these exceed 88 characters
assert something_long == something_else_very_long.method_call(
x
) |
I suspect most of these problems stem from the fact that black doesn't consider all possible parenthesis while doing I'm toying with a change that converts all invisible parenthesis to visible before doing the formatting, but haven't yet figured out how to eliminate "useless" ones afterwards yet. |
It would be a simpler change to change |
I agree that would result in simpler code in Black, but in cases where there's only one delimiter with max priority and it's towards the end of the line, it ends up being subjectively worse in my opinion. Case in point:
or a more extreme example:
|
On the other hand, your suggestion would make the examples in #348 look better. I'll try that version internally and see the effect. |
These are some other terrible examples:
It breaks some fluent interfaces:
These are all probably fixable by sprinkling some more heuristics in |
Possible way to I do not know how black annotates individual characters - if it annotates them at all. Eg. str would get converted to txt = "if a == b and c == d:"
astr = AnnotatedStr(txt)
assert astr.text_raw == txt
astr.show_annotated == "if (a == b) and (c == d):" Then to get the formatted = "".join(
ch for ch in asrt.show_annotated if ch == " " or ch in asrt.text_raw
) |
#762 fixed broken code, but in many cases the old, broken code produced subjectively better formatting, especially (in my experience) around assert statements.
Let's consider whether there's a way to improve the formatting in cases that were affected by #762.
It would be helpful to add examples to this issue of formatting changes caused by #762 that may not be improvements.
The text was updated successfully, but these errors were encountered: