<commit_before>"""Signal pattern matching."""

import re


class PatternError(Exception):
    """Pattern error."""


class Pattern:
    """Signal pattern representation."""

    PATTERN_REGEX = re.compile(r"[01xX]+")

    def __init__(self, pattern: str):
        """Initialize."""
        if not isinstance(pattern, str):
            raise TypeError("pattern must be a string")
        m = self.PATTERN_REGEX.match(pattern)
        if m is None:
            raise PatternError("pattern is invalid")

        self._pattern = pattern

    @property
    def pattern(self):
        """Get pattern."""
        return self._pattern

    def __len__(self):
        """Get length."""
        return len(self._pattern)

    def match(self, value):
        """Match against value."""
        if not isinstance(value, str):
            raise TypeError("value must be string")
        if len(value) != len(self._pattern):
            raise ValueError("cannot compare, different lengths")
        for value_bit, expected_bit in zip(value, self._pattern):
            if expected_bit in ("x", "X"):
                # don't care
                continue
            if expected_bit != value_bit:
                return False

        return True<commit_msg>add typing<commit_after>"""Signal pattern matching."""

import re


class PatternError(Exception):
    """Pattern error."""


class Pattern:
    """Signal pattern representation."""

    PATTERN_REGEX = re.compile(r"[01xX]+")

    def __init__(self, pattern: str):
        """Initialize."""
        if not isinstance(pattern, str):
            raise TypeError("pattern must be a string")
        m = self.PATTERN_REGEX.match(pattern)
        if m is None:
            raise PatternError("pattern is invalid")

        self._pattern = pattern

    @property
    def pattern(self):
        """Get pattern."""
        return self._pattern

    def __len__(self):
        """Get length."""
        return len(self._pattern)

    def match(self, value: str) -> bool:
        """Match against value."""
        if not isinstance(value, str):
            raise TypeError("value must be string")
        if len(value) != len(self._pattern):
            raise ValueError("cannot compare, different lengths")
        for value_bit, expected_bit in zip(value, self._pattern):
            if expected_bit in ("x", "X"):
                # don't care
                continue
            if expected_bit != value_bit:
                return False

        return True
{'fraction_non_alphanumeric': 0.11738782051282051, 'fraction_numerical': 0.0016025641025641025, 'mean_word_length': 2.1290726817042605, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3686502', 'n_tokens_mistral': 661, 'n_tokens_neox': 630, 'n_words': 202}