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

Function convert

src/blib2to3/pytree.py:470–487  ·  view source on GitHub ↗

Convert raw node information to a Node or Leaf instance. This is passed to the parser driver which calls it whenever a reduction of a grammar rule produces a new complete node, so that the tree is build strictly bottom-up.

(gr: Grammar, raw_node: RawNode)

Source from the content-addressed store, hash-verified

468
469
470def convert(gr: Grammar, raw_node: RawNode) -> NL:
471 """
472 Convert raw node information to a Node or Leaf instance.
473
474 This is passed to the parser driver which calls it whenever a reduction of a
475 grammar rule produces a new complete node, so that the tree is build
476 strictly bottom-up.
477 """
478 type, value, context, children = raw_node
479 if children or type in gr.number2symbol:
480 # If there's exactly one child, return that child instead of
481 # creating a new node.
482 assert children is not None
483 if len(children) == 1:
484 return children[0]
485 return Node(type, children, context=context)
486 else:
487 return Leaf(type, value or "", context=context)
488
489
490_Results = dict[str, NL]

Callers 2

shiftMethod · 0.90
popMethod · 0.90

Calls 2

NodeClass · 0.85
LeafClass · 0.85

Tested by

no test coverage detected