MCPcopy
hub / github.com/psf/black / wrap_in_parentheses

Function wrap_in_parentheses

src/black/nodes.py:990–1005  ·  view source on GitHub ↗

Wrap `child` in parentheses. This replaces `child` with an atom holding the parentheses and the old child. That requires moving the prefix. If `visible` is False, the leaves will be valueless (and thus invisible).

(parent: Node, child: LN, *, visible: bool = True)

Source from the content-addressed store, hash-verified

988
989
990def wrap_in_parentheses(parent: Node, child: LN, *, visible: bool = True) -> None:
991 """Wrap `child` in parentheses.
992
993 This replaces `child` with an atom holding the parentheses and the old
994 child. That requires moving the prefix.
995
996 If `visible` is False, the leaves will be valueless (and thus invisible).
997 """
998 lpar = Leaf(token.LPAR, "(" if visible else "")
999 rpar = Leaf(token.RPAR, ")" if visible else "")
1000 prefix = child.prefix
1001 child.prefix = ""
1002 index = child.remove() or 0
1003 new_child = Node(syms.atom, [lpar, child, rpar])
1004 new_child.prefix = prefix
1005 parent.insert_child(index, new_child)
1006
1007
1008def unwrap_singleton_parenthesis(node: LN) -> LN | None:

Callers 8

visit_dictsetmakerMethod · 0.90
visit_funcdefMethod · 0.90
visit_simple_stmtMethod · 0.90
visit_powerMethod · 0.90
visit_tnameMethod · 0.90
remove_await_parensFunction · 0.90
remove_with_parensFunction · 0.90

Calls 4

LeafClass · 0.90
NodeClass · 0.90
removeMethod · 0.80
insert_childMethod · 0.80

Tested by

no test coverage detected