import ast


def prettyprint_ast(node, show_attributes=False):
    """Better version of ast.dump that formats things nicely"""
    more = '    '
    def format(node, indent):
        if isinstance(node, ast.AST):
            body = []

            if node._fields:
                body += list(
                    '%s=%s' % (field, format(getattr(node, field), indent + more))
                    for field in node._fields
                )
            if show_attributes and node._attributes:
                body += list(
                    '%s=%s' % (a, format(getattr(node, a), indent + more))
                    for a in node._attributes
                )
            total_length = sum(len(stmt) for stmt in body) + len(body) * 2 + len(indent)
            if any("\n" in stmt for stmt in body) or total_length >= 80:
                inner = indent + more + (",\n" + indent + more).join(body) + "\n" + indent
                return node.__class__.__name__ + '(\n' + inner + ')'
            else:
                return node.__class__.__name__ + "(" + ", ".join(attr for attr in body) + ")"

        elif isinstance(node, list):
            if len(node) == 0:
                return '[]'
            else:
                return '[\n' + ',\n'.join(indent + more + format(x, indent + more) for x in node) + '\n' + indent + ']'
        return repr(node)
    if not isinstance(node, ast.AST):
        raise TypeError('expected AST, got %r' % node.__class__.__name__)
    return format(node, '')