<commit_before>from django_performance_testing.signals import result_collected


class BaseLimit(object):

    def __init__(self, collector_id=None):
        self.collector_id = collector_id
        if self.is_anonymous():
            self.collector = self.collector_cls()
        else:
            if self.collector_id not in self.collector_cls._ids:
                raise TypeError(
                    'There is no collector named {!r}'.format(collector_id))
            self.connect_for_results()
            self.collector = None

    def __enter__(self):
        if self.is_anonymous():
            self.connect_for_results()
            self.collector.__enter__()
        return self

    def connect_for_results(self):
        result_collected.connect(self.result_collected_handler)

    def __exit__(self, exc_type, exc_val, exc_tb):
        if self.is_anonymous():
            self.collector.__exit__(exc_type, exc_val, exc_tb)
            result_collected.disconnect(self.result_collected_handler)

    def is_anonymous(self):
        return self.collector_id is None

    def result_collected_handler(self, signal, sender, result, extra_context):
        if not self.is_anonymous():<commit_msg>must have kwargs for signal handler<commit_after>from django_performance_testing.signals import result_collected


class BaseLimit(object):

    def __init__(self, collector_id=None):
        self.collector_id = collector_id
        if self.is_anonymous():
            self.collector = self.collector_cls()
        else:
            if self.collector_id not in self.collector_cls._ids:
                raise TypeError(
                    'There is no collector named {!r}'.format(collector_id))
            self.connect_for_results()
            self.collector = None

    def __enter__(self):
        if self.is_anonymous():
            self.connect_for_results()
            self.collector.__enter__()
        return self

    def connect_for_results(self):
        result_collected.connect(self.result_collected_handler)

    def __exit__(self, exc_type, exc_val, exc_tb):
        if self.is_anonymous():
            self.collector.__exit__(exc_type, exc_val, exc_tb)
            result_collected.disconnect(self.result_collected_handler)

    def is_anonymous(self):
        return self.collector_id is None

    def result_collected_handler(
            self, signal, sender, result, extra_context, **kwargs):
        assert kwargs == {}, 'expected no kwargs, but got {!r}'.format(kwargs)
        if not self.is_anonymous():
{'fraction_non_alphanumeric': 0.08477917981072555, 'fraction_numerical': 0.0, 'mean_word_length': 2.6191155492154063, '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': '7639868', 'n_tokens_mistral': 745, 'n_tokens_neox': 721, 'n_words': 152}