<commit_before>from node import TYPE_OPERATOR
import re


# Each rule will append its hint message to the following dictionary. The
# function pointer to the apply function of the rule is used as key. The
# corresponding value is a string, which will be used to produce the hint
# message. The string will be processed using string.format().
MESSAGES = {}


class Possibility(object):
    def __init__(self, root, handler, args=()):
        self.root = root
        self.handler = handler
        self.args = args

    def __str__(self):
        if self.handler in MESSAGES:
            msg = MESSAGES[self.handler]

            # Surround math notation with backticks. If there are any backticks
            # already, do not add additional backticks. The add_backticks
            # lambda is necessary otherwise because \1 and \2 are not matched
            # both at the same time.
            add_backticks = lambda x: '`%s`' % ''.join(x.groups(''))
            msg = re.sub('`([^`]*)`|\(?({[^. ]+)', add_backticks, msg)

            if callable(msg):
                msg = msg(self.root, self.args)

            return msg.format(self.root, *self.args)

        return repr(self)

    def __repr__(self):
        return '<Possibility root="%s" handler=%s args=%s>' \
                % (self.root, self.handler.func_name, self.args)

    def __eq__(self, other):
        """
        Use node hash comparison when comparing to other Possibility to assert
        that its is the same object as in this one.
        """
        return self.handler == other.handler \
               and hash(self.root) == hash(other.root) \<commit_msg>Math notation is now correctly applied in callable messages.<commit_after>from node import TYPE_OPERATOR
import re


# Each rule will append its hint message to the following dictionary. The
# function pointer to the apply function of the rule is used as key. The
# corresponding value is a string, which will be used to produce the hint
# message. The string will be processed using string.format().
MESSAGES = {}


class Possibility(object):
    def __init__(self, root, handler, args=()):
        self.root = root
        self.handler = handler
        self.args = args

    def __str__(self):
        if self.handler in MESSAGES:
            msg = MESSAGES[self.handler]

            if callable(msg):
                msg = msg(self.root, self.args)

            # Surround math notation with backticks. If there are any backticks
            # already, do not add additional backticks. The add_backticks
            # lambda is necessary otherwise because \1 and \2 are not matched
            # both at the same time.
            add_backticks = lambda x: '`%s`' % ''.join(x.groups(''))
            msg = re.sub('`([^`]*)`|\(?({[^. ]+)', add_backticks, msg)

            return msg.format(self.root, *self.args)

        return repr(self)

    def __repr__(self):
        return '<Possibility root="%s" handler=%s args=%s>' \
                % (self.root, self.handler.func_name, self.args)

    def __eq__(self, other):
        """
        Use node hash comparison when comparing to other Possibility to assert
        that its is the same object as in this one.
        """
        return self.handler == other.handler \
               and hash(self.root) == hash(other.root) \
{'fraction_non_alphanumeric': 0.10261811616009629, 'fraction_numerical': 0.0012037315678603672, 'mean_word_length': 2.2845849802371543, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4361548', 'n_tokens_mistral': 940, 'n_tokens_neox': 902, 'n_words': 344}