google / yapf

A formatter for Python files
Apache License 2.0
13.78k stars 892 forks source link

EACH_DICT_ENTRY_ON_SEPARATE_LINE for OrderedDict? #468

Open concretevitamin opened 7 years ago

concretevitamin commented 7 years ago

Here's a diff before and after yapf with google style:

-all_processes = OrderedDict([(PROCESS_TYPE_MONITOR, []),
-                             (PROCESS_TYPE_LOG_MONITOR, []),
-                             (PROCESS_TYPE_WORKER, []),
-                             (PROCESS_TYPE_LOCAL_SCHEDULER, []),
-                             (PROCESS_TYPE_PLASMA_MANAGER, []),
-                             (PROCESS_TYPE_PLASMA_STORE, []),
-                             (PROCESS_TYPE_GLOBAL_SCHEDULER, []),
-                             (PROCESS_TYPE_REDIS_SERVER, []),
-                             (PROCESS_TYPE_WEB_UI, [])],)
+all_processes = OrderedDict(
+    [(PROCESS_TYPE_MONITOR, []), (PROCESS_TYPE_LOG_MONITOR, []),
+     (PROCESS_TYPE_WORKER, []), (PROCESS_TYPE_LOCAL_SCHEDULER,
+                                 []), (PROCESS_TYPE_PLASMA_MANAGER, []),
+     (PROCESS_TYPE_PLASMA_STORE, []), (PROCESS_TYPE_GLOBAL_SCHEDULER,
+                                       []), (PROCESS_TYPE_REDIS_SERVER,
+                                             []), (PROCESS_TYPE_WEB_UI, [])], )

I think we can agree the before version is more readable ;) I can think of several possibilities:

flunderpero commented 7 years ago

Another workaround would be to enable the knob split_arguments_when_comma_terminated=True (which imho is a good idea anyway) and add a , after the last element of the array. Each element will then be put on a separate line.

concretevitamin commented 7 years ago

That works! I will leave this open in case the maintainers decide a direct solution is desirable.

bwendling commented 7 years ago

What @flunderpero suggested is the recommended way of "fixing" this. There might be a better heuristic we can apply here, but it will take a bit of thinking...