<commit_before>"""
The :mod:`Diagnostic` module provides several commonly useful
algorithms that operate on abstract syntax trees.
"""

from __future__ import absolute_import, division, print_function, unicode_literals
from . import ast

class Visitor:
    """
    A node visitor base class that does a traversal
    of the abstract syntax tree.

    This class is meant to be subclassed, with the subclass adding
    visitor methods. The visitor method should call ``self.generic_visit(node)``
    to continue the traversal; this allows to perform arbitrary
    actions both before and after traversing the children of a node.

    The visitor methods for the nodes are ``'visit_'`` +
    class name of the node.  So a `Try` node visit function would
    be `visit_Try`.
    """

    def generic_visit(self, node):
        """Called if no explicit visitor function exists for a node."""
        for field_name in node._fields:
            self.visit(getattr(node, field_name))

    def _visit_one(self, node):
        visit_attr = "visit_" + type(node).__name__
        if hasattr(self, visit_attr):
            getattr(self, visit_attr)(node)
        else:
            self.generic_visit(node)

    def visit(self, obj):
        """Visit a node or a list of nodes. Other values are ignored"""
        if isinstance(obj, list):
            for elt in obj:
                self.visit(elt)
        elif isinstance(obj, ast.AST):
            self._visit_one(obj)

class Transformer:
    """<commit_msg>algorithm.Visitor: return the value of the visitor method from visit().<commit_after>"""
The :mod:`Diagnostic` module provides several commonly useful
algorithms that operate on abstract syntax trees.
"""

from __future__ import absolute_import, division, print_function, unicode_literals
from . import ast

class Visitor:
    """
    A node visitor base class that does a traversal
    of the abstract syntax tree.

    This class is meant to be subclassed, with the subclass adding
    visitor methods. The visitor method should call ``self.generic_visit(node)``
    to continue the traversal; this allows to perform arbitrary
    actions both before and after traversing the children of a node.

    The visitor methods for the nodes are ``'visit_'`` +
    class name of the node.  So a `Try` node visit function would
    be `visit_Try`.
    """

    def generic_visit(self, node):
        """Called if no explicit visitor function exists for a node."""
        for field_name in node._fields:
            self.visit(getattr(node, field_name))

    def _visit_one(self, node):
        visit_attr = "visit_" + type(node).__name__
        if hasattr(self, visit_attr):
            return getattr(self, visit_attr)(node)
        else:
            return self.generic_visit(node)

    def visit(self, obj):
        """Visit a node or a list of nodes. Other values are ignored"""
        if isinstance(obj, list):
            [self.visit(elt) for elt in obj]
        elif isinstance(obj, ast.AST):
            return self._visit_one(obj)

class Transformer:
    """
{'fraction_non_alphanumeric': 0.08289817232375979, 'fraction_numerical': 0.0, 'mean_word_length': 2.874841972187105, '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': '2455633', 'n_tokens_mistral': 831, 'n_tokens_neox': 813, 'n_words': 338}