<commit_before># -*- coding: utf-8 -*-

"""
Visualize an AST.
"""

from __future__ import print_function, division, absolute_import

import os
import ast
import textwrap
from itertools import chain, imap, ifilter

from numba.viz.graphviz import render

# ______________________________________________________________________
# AST Constants

ast_constant_classes = (
    ast.expr_context,
    ast.operator,
    ast.unaryop,
    ast.cmpop,
)

# ______________________________________________________________________
# Utilities

is_ast = lambda node: (isinstance(node, (ast.AST, list)) and not
                       isinstance(node, ast_constant_classes))

class SomeConstant(object):
    def __init__(self, value):
        self.value = value
    def __repr__(self):
        return repr(self.value)

def make_list(node):
    if isinstance(node, list):
        return node
    elif isinstance(node, ast.AST):
        return [node]
    else:
        return [SomeConstant(node)]

def nodes(node):
    return [getattr(node, attr) for attr in node._fields]

def fields(node):
    return zip(node._fields, nodes(node))

# ______________________________________________________________________
# Adaptor

class ASTGraphAdaptor(object):

    def children(self, node):
        return list(chain(*imap(make_list, ifilter(is_ast, nodes(node)))))
<commit_msg>Fix dump-ast issue when doing fancy rendering<commit_after># -*- coding: utf-8 -*-

"""
Visualize an AST.
"""

from __future__ import print_function, division, absolute_import

import os
import ast
import textwrap
from itertools import chain, imap, ifilter

from numba.viz.graphviz import render

# ______________________________________________________________________
# AST Constants

ast_constant_classes = (
    ast.expr_context,
    ast.operator,
    ast.unaryop,
    ast.cmpop,
)

# ______________________________________________________________________
# Utilities

is_ast = lambda node: (isinstance(node, (ast.AST, list)) and not
                       isinstance(node, ast_constant_classes))

class SomeConstant(object):
    def __init__(self, value):
        self.value = value
    def __repr__(self):
        return repr(self.value)

def make_list(node):
    if isinstance(node, list):
        return node
    elif isinstance(node, ast.AST):
        return [node]
    else:
        return [SomeConstant(node)]

def nodes(node):
    return [getattr(node, attr, None) for attr in node._fields]

def fields(node):
    return zip(node._fields, nodes(node))

# ______________________________________________________________________
# Adaptor

class ASTGraphAdaptor(object):

    def children(self, node):
        return list(chain(*imap(make_list, ifilter(is_ast, nodes(node)))))

{'fraction_non_alphanumeric': 0.09436722750548647, 'fraction_numerical': 0.000731528895391368, 'mean_word_length': 4.055452865064695, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2181981', 'n_tokens_mistral': 765, 'n_tokens_neox': 754, 'n_words': 199}