"Append a piece of text to the current line."
        self.f.write(text)
[docs]    def enter(self):
        "Print ':', and increase the indentation."
        self.write(":")
        self._indent += 1
[docs]    def leave(self):
        "Decrease the indentation level."
        self._indent -= 1
[docs]    def dispatch(self, tree):
        "Dispatcher function, dispatching tree type T to method _T."
        if isinstance(tree, list):
            for t in tree:
                self.dispatch(t)
            return
        meth = getattr(self, "_" + tree.__class__.__name__)
        meth(tree)
    ############### Unparsing methods ######################
    # There should be one method per concrete grammar type #
    # Constructors should be grouped by sum type. Ideally, #
    # this would follow the order in the grammar, but      #
    # currently doesn't.                                   #
    ########################################################
    def _Module(self, tree):
        for stmt in tree.body:
            self.dispatch(stmt)
    # stmt
    def _Expr(self, tree):
        self.fill()
        self.dispatch(tree.value)
    def _NamedExpr(self, tree):
        self.write("(")
        self.dispatch(tree.target)
        self.write(" := ")
        self.dispatch(tree.value)
        self.write(")")
    def _Import(self, t):
        self.fill("import ")
        interleave(lambda: self.write(", "), self.dispatch, t.names)
    def _ImportFrom(self, t):
        self.fill("from ")
        self.write("." * t.level)
        if t.module:
            self.write(t.module)
        self.write(" import ")