Repository: google/yapf

Issue:
Regression in formatting an argument expansion in a dictionary
`{a: b(*c)}` gets formatted to `{a: b( * c)}`

This regression occured in f30c1d26df3449950d95982f17568d03fe4a361f

Discussion:

Patch:
diff --git a/yapf/yapflib/subtype_assigner.py b/yapf/yapflib/subtype_assigner.py
index f8c24cd..34391b3 100644
--- a/yapf/yapflib/subtype_assigner.py
+++ b/yapf/yapflib/subtype_assigner.py
@@ -73,7 +73,11 @@ class _SubtypeAssigner(pytree_visitor.PyTreeVisitor):
             self._SetFirstLeafTokenSubtype(child,
                                            format_token.Subtype.DICTIONARY_KEY)
           elif last_was_colon:
-            self._SetSubtypeRec(child, format_token.Subtype.DICTIONARY_VALUE)
+            if pytree_utils.NodeName(child) == 'power':
+              self._SetFirstLeafTokenSubtype(child,
+                                             format_token.Subtype.DICTIONARY_VALUE)
+            else:
+              self._SetSubtypeRec(child, format_token.Subtype.DICTIONARY_VALUE)
         last_was_comma = isinstance(child, pytree.Leaf) and child.value == ','
         last_was_colon = isinstance(child, pytree.Leaf) and child.value == ':'
       self.Visit(child)


Test patch:
diff --git a/yapftests/reformatter_test.py b/yapftests/reformatter_test.py
index bd88849..7e35c8b 100644
--- a/yapftests/reformatter_test.py
+++ b/yapftests/reformatter_test.py
@@ -1217,6 +1217,11 @@ format_token.Subtype.NONE))
     uwlines = _ParseAndUnwrap(code)
     self.assertCodeEqual(code, reformatter.Reformat(uwlines))
 
+  def testFunctionCallInDict(self):
+    code = "a = {'a': b(c=d, **e)}\n"
+    uwlines = _ParseAndUnwrap(code)
+    self.assertCodeEqual(code, reformatter.Reformat(uwlines))
+
 
 class BuganizerFixes(ReformatterTest):