<commit_before># -*- encoding: utf-8 -*-
from __future__ import print_function
import abc
from abjad.tools import abctools
from abjad.tools import datastructuretools
from abjad.tools import instrumenttools
from abjad.tools import pitchtools
from abjad.tools import systemtools
from abjad.tools.topleveltools import inspect_


class PitchHandler(abctools.AbjadValueObject):

    ### CLASS VARIABLES ###

    __slots__ = (
        '_chord_expressions',
        '_forbid_repetitions',
        '_hash',
        '_pitch_application_rate',
        '_transform_stack',
        )

    ### INITIALIZER ###

    def __init__(
        self,
        forbid_repetitions=None,
        chord_expressions=None,
        pitch_application_rate=None,
        transform_stack=None,
        ):
        import consort
        if forbid_repetitions is not None:
            forbid_repetitions = bool(forbid_repetitions)
        self._forbid_repetitions = forbid_repetitions
        if chord_expressions is not None:
            prototype = (
                consort.ChordExpression,
                consort.KeyClusterExpression,
                )
            assert chord_expressions
            assert all(isinstance(x, prototype) for x in chord_expressions)
            chord_expressions = datastructuretools.CyclicTuple(
                chord_expressions,
                )
        self._chord_expressions = chord_expressions
        self._hash = None
        assert pitch_application_rate in (
            None, 'logical_tie', 'division', 'phrase',
            )
        self._pitch_application_rate = pitch_application_rate
        if transform_stack is not None:
            prototype = (
                pitchtools.Inversion,
                pitchtools.Multiplication,
                pitchtools.Transposition,
                )
            assert all(isinstance(_, prototype) for _ in transform_stack)
            transform_stack = tuple(transform_stack)
        self._transform_stack = transform_stack

    ### SPECIAL METHODS ###

    @abc.abstractmethod
    def __call__(
        self,
        logical_tie,
        attack_point_signature,
        phrase_seed,
        pitch_range,
        previous_pitch,
        seed,
        transposition,
        ):
        raise NotImplementedError

    def __eq__(self, expr):
        if isinstance(expr, type(self)):
            if format(self) == format(expr):
                return True
        return False

    def __hash__(self):
        if self._hash is None:
            hash_values = (type(self), format(self))
            self._hash = hash(hash_values)
        return self._hash
<commit_msg>Improved error messaging in PitchHandler.<commit_after># -*- encoding: utf-8 -*-
from __future__ import print_function
import abc
from abjad.tools import abctools
from abjad.tools import datastructuretools
from abjad.tools import instrumenttools
from abjad.tools import pitchtools
from abjad.tools import systemtools
from abjad.tools.topleveltools import inspect_


class PitchHandler(abctools.AbjadValueObject):

    ### CLASS VARIABLES ###

    __slots__ = (
        '_chord_expressions',
        '_forbid_repetitions',
        '_hash',
        '_pitch_application_rate',
        '_transform_stack',
        )

    ### INITIALIZER ###

    def __init__(
        self,
        forbid_repetitions=None,
        chord_expressions=None,
        pitch_application_rate=None,
        transform_stack=None,
        ):
        import consort
        if forbid_repetitions is not None:
            forbid_repetitions = bool(forbid_repetitions)
        self._forbid_repetitions = forbid_repetitions
        if chord_expressions is not None:
            prototype = (
                consort.ChordExpression,
                consort.KeyClusterExpression,
                )
            assert chord_expressions, chord_expressions
            assert all(isinstance(x, prototype) for x in chord_expressions), \
                chord_expressions
            chord_expressions = datastructuretools.CyclicTuple(
                chord_expressions,
                )
        self._chord_expressions = chord_expressions
        self._hash = None
        assert pitch_application_rate in (
            None, 'logical_tie', 'division', 'phrase',
            )
        self._pitch_application_rate = pitch_application_rate
        if transform_stack is not None:
            prototype = (
                pitchtools.Inversion,
                pitchtools.Multiplication,
                pitchtools.Transposition,
                )
            assert all(isinstance(_, prototype) for _ in transform_stack), \
                transform_stack
            transform_stack = tuple(transform_stack)
        self._transform_stack = transform_stack

    ### SPECIAL METHODS ###

    @abc.abstractmethod
    def __call__(
        self,
        logical_tie,
        attack_point_signature,
        phrase_seed,
        pitch_range,
        previous_pitch,
        seed,
        transposition,
        ):
        raise NotImplementedError

    def __eq__(self, expr):
        if isinstance(expr, type(self)):
            if format(self) == format(expr):
                return True
        return False

    def __hash__(self):
        if self._hash is None:
            hash_values = (type(self), format(self))
            self._hash = hash(hash_values)
        return self._hash

{'fraction_non_alphanumeric': 0.06843965036265576, 'fraction_numerical': 0.0003719546215361726, 'mean_word_length': 2.0230466554243955, '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': '1657979', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1418, 'n_words': 317}