Repository: psf/black

Issue:
`wrap_long_dict_value_in_parens` can introduce unnecessary nesting for dicts in dicts
Originally reported at https://github.com/psf/black/issues/4042#issuecomment-1852645541

Repro:
```
class Random:
    def func():
        random_service.status.active_states.inactive = (
            make_new_top_level_state_from_dict(
                {
                    "topLevelBase": {
                        "secondaryBase": {
                            "timestamp": 1234,
                            "latitude": 1,
                            "longitude": 2,
                            "actionTimestamp": Timestamp(
                                seconds=1530584000, nanos=0
                            ).ToJsonString(),
                        }
                    },
                }
            )
        )
```

Enabling just `wrap_long_dict_value_in_parens` turns this into:
```
class Random:
    def func():
        random_service.status.active_states.inactive = (
            make_new_top_level_state_from_dict(
                {
                    "topLevelBase": (
                        {
                            "secondaryBase": (
                                {
                                    "timestamp": 1234,
                                    "latitude": 1,
                                    "longitude": 2,
                                    "actionTimestamp": (
                                        Timestamp(
                                            seconds=1530584000, nanos=0
                                        ).ToJsonString()
                                    ),
                                }
                            )
                        }
                    ),
                }
            )
        )
```


Discussion:

Resolving patch:
diff --git a/src/black/linegen.py b/src/black/linegen.py
--- a/src/black/linegen.py
+++ b/src/black/linegen.py
@@ -244,15 +244,14 @@ def visit_dictsetmaker(self, node: Node) -> Iterator[Line]:
                 if node.children[i - 1].type == token.COLON:
                     if (
                         child.type == syms.atom
-                        and child.children[0].type == token.LPAR
+                        and child.children[0].type in OPENING_BRACKETS
                         and not is_walrus_assignment(child)
                     ):
-                        if maybe_make_parens_invisible_in_atom(
+                        maybe_make_parens_invisible_in_atom(
                             child,
                             parent=node,
                             remove_brackets_around_comma=False,
-                        ):
-                            wrap_in_parentheses(node, child, visible=False)
+                        )
                     else:
                         wrap_in_parentheses(node, child, visible=False)
         yield from self.visit_default(node)


Test patch:
diff --git a/tests/data/cases/preview_long_dict_values.py b/tests/data/cases/preview_long_dict_values.py
--- a/tests/data/cases/preview_long_dict_values.py
+++ b/tests/data/cases/preview_long_dict_values.py
@@ -37,6 +37,26 @@
 }
 
 
+class Random:
+    def func():
+        random_service.status.active_states.inactive = (
+            make_new_top_level_state_from_dict(
+                {
+                    "topLevelBase": {
+                        "secondaryBase": {
+                            "timestamp": 1234,
+                            "latitude": 1,
+                            "longitude": 2,
+                            "actionTimestamp": Timestamp(
+                                seconds=1530584000, nanos=0
+                            ).ToJsonString(),
+                        }
+                    },
+                }
+            )
+        )
+
+
 # output
 
 
@@ -89,3 +109,21 @@
         }
     ),
 }
+
+
+class Random:
+    def func():
+        random_service.status.active_states.inactive = (
+            make_new_top_level_state_from_dict({
+                "topLevelBase": {
+                    "secondaryBase": {
+                        "timestamp": 1234,
+                        "latitude": 1,
+                        "longitude": 2,
+                        "actionTimestamp": (
+                            Timestamp(seconds=1530584000, nanos=0).ToJsonString()
+                        ),
+                    }
+                },
+            })
+        )