Split before function call in list
If the whole list cannot fit on a single line, then split before a function
call. This prevents things like this:
def foo():
return [
Bar(
xxx='some string',
yyy='another long string',
zzz='a third long string'), Bar(
xxx='some string',
yyy='another long string',
zzz='a third long string')
]
diff --git a/yapftests/reformatter_buganizer_test.py b/yapftests/reformatter_buganizer_test.py
index 1bdac25..8eed74b 100644
--- a/yapftests/reformatter_buganizer_test.py
+++ b/yapftests/reformatter_buganizer_test.py
@@ -28,6 +28,45 @@
def setUpClass(cls):
style.SetGlobalStyle(style.CreateChromiumStyle())
+ def testB36806207(self):
+ unformatted_code = textwrap.dedent("""\
+ def _():
+ linearity_data = [[row] for row in [
+ "%.1f mm" % (np.mean(linearity_values["pos_error"]) * 1000.0),
+ "%.1f mm" % (np.max(linearity_values["pos_error"]) * 1000.0),
+ "%.1f mm" % (np.mean(linearity_values["pos_error_chunk_mean"]) * 1000.0),
+ "%.1f mm" % (np.max(linearity_values["pos_error_chunk_max"]) * 1000.0),
+ "%.1f deg" % math.degrees(np.mean(linearity_values["rot_noise"])),
+ "%.1f deg" % math.degrees(np.max(linearity_values["rot_noise"])),
+ "%.1f deg" % math.degrees(np.mean(linearity_values["rot_drift"])),
+ "%.1f deg" % math.degrees(np.max(linearity_values["rot_drift"])),
+ "%.1f%%" % (np.max(linearity_values["pos_discontinuity"]) * 100.0),
+ "%.1f%%" % (np.max(linearity_values["rot_discontinuity"]) * 100.0)
+ ]]
+ """)
+ expected_code = textwrap.dedent("""\
+ def _():
+ linearity_data = [
+ [row]
+ for row in [
+ "%.1f mm" % (np.mean(linearity_values["pos_error"]) * 1000.0),
+ "%.1f mm" % (np.max(linearity_values["pos_error"]) * 1000.0),
+ "%.1f mm" % (
+ np.mean(linearity_values["pos_error_chunk_mean"]) * 1000.0),
+ "%.1f mm" % (
+ np.max(linearity_values["pos_error_chunk_max"]) * 1000.0),
+ "%.1f deg" % math.degrees(np.mean(linearity_values["rot_noise"])),
+ "%.1f deg" % math.degrees(np.max(linearity_values["rot_noise"])),
+ "%.1f deg" % math.degrees(np.mean(linearity_values["rot_drift"])),
+ "%.1f deg" % math.degrees(np.max(linearity_values["rot_drift"])),
+ "%.1f%%" % (np.max(linearity_values["pos_discontinuity"]) * 100.0),
+ "%.1f%%" % (np.max(linearity_values["rot_discontinuity"]) * 100.0)
+ ]
+ ]
+ """)
+ uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+ self.assertEqual(expected_code, reformatter.Reformat(uwlines))
+
def testB36215507(self):
code = textwrap.dedent("""\
class X():