for z in node.body:
    self.level += 1
result.append(self.visit(z))
self.level -= 1
if node.orelse:
    tail = self.tail_after_body(node.body, node.orelse, result)
result.append(self.indent('else:' + tail))
for z in node.orelse:
    self.level += 1
result.append(self.visit(z))
self.level -= 1
return ''.join(result)
Python AST с сохраненными комментариями