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
F: linebreakHow should we split up lines?F: symmetryFixing this would require Black to understand symmetry.T: enhancementNew feature or requestT: styleWhat do we want Blackened code to look like?help wantedExtra attention is needed
Probably not a bug, but I was wondering if the code below shouldn't be formatted more like call chains are.
I did not expect black to change anything other than quotes in this example.
Aligned brackets feel much more readable.
# before
- search_fields = (
- ['file__%s' % field for field in FileAdmin.search_fields] +
- ['resource__%s' % field for field in ResourceAdmin.search_fields]
- )
# black output
+ search_fields = ["file__%s" % field for field in FileAdmin.search_fields] + [
+ "resource__%s" % field for field in ResourceAdmin.search_fields
+ ]
Operating system: OSX 10.11.6
Python version: 3.6.5
Black version: 18.5b0
Does also happen on master: yes
Reacted by Łukasz Langa, nyanpasu64 and Rémy Taymans
Agreed with you on this particular case. It's a case of over-optimization that we decided to do due to a popular idiom in assignments and if statements:
if there is just a single operator; and
the line up to and including the operator is short enough; and
the rest ends with a bracket (so we have something to split on); then
omit optional parentheses and split by the discovered bracket instead.
We should extend this rule to discover symmetrical cases like yours.
The extra bracket has a purpose: it provides the line continuation, but unfortunately it also costs an extra line. However if it is not there, some other bracket needs to provide line continuation, which is quite awkward looking.
I have just added some more examples in #317 with reasoning why the popular idiom is bad in general. But maybe I miss something, is there any example, where this idiom produces a good result?
F: linebreakHow should we split up lines?F: symmetryFixing this would require Black to understand symmetry.T: enhancementNew feature or requestT: styleWhat do we want Blackened code to look like?help wantedExtra attention is needed
Activity
ambv commentedon May 26, 2018
Agreed with you on this particular case. It's a case of over-optimization that we decided to do due to a popular idiom in assignments and if statements:
omit optional parentheses and split by the discovered bracket instead.
We should extend this rule to discover symmetrical cases like yours.
e3krisztian commentedon Jun 8, 2018
Maybe this rule should be eliminated instead?
The extra bracket has a purpose: it provides the line continuation, but unfortunately it also costs an extra line. However if it is not there, some other bracket needs to provide line continuation, which is quite awkward looking.
I have just added some more examples in #317 with reasoning why the popular idiom is bad in general. But maybe I miss something, is there any example, where this idiom produces a good result?