<commit_before>from .tag import Tag

class UnknownTag(Tag):
    """
    Defines a mult-value unrecognized tag object

    These are special tag objects that represent an unexpected or unknown tag.
    They are added automatically when attempting to access a tag that was not
    initialized.

    These tags cannot be required and will always be invalid in strict mode.
    """
    def __init__(self, name: str, *args, hidden: bool=False, limit: int=-1):
        """
        Create a new Tag object

        Args:
            hidden (bool): Whether this tag should be displayed in character
                listings. When present, a coresponding @hide tag will be
                generated by to_header.
            limit (int): Maximum number of values allowed in the tag. Passing a
                negative number allows an infinite number of values to be
                stored.
            values (list): Initial values to save
        """
        super().__init__(name, *args, required=False, hidden=hidden, limit=limit)

    def __repr__(self):
        return "{}({}, {}, hidden={}, limit={})".format(
            type(self).__name__,
            self.name,
            *self.data,
            self.hidden,
            self.limit
        )

    def validate(self, strict=False):
        """
        Validate this tag's attributes

        Validations:
            * Required is incompatible with a limit of zero
            * (strict) If limit is non-negative, the total values must be <= limit
            * (strict) This tag is always invalid in strict mode

        Args:
            strict (bool): Whether to report non-critical errors and omissions

        Returns:
            True if this tag has no validation problems, false if not
        """
        super().validate(strict=strict)

        if strict:
            self.problems.append("Unrecognized tag '{}'".format(self.name))

        return self.valid

    def to_header(self):
        """
        Generate a text header representation of this tag

        This creates the appropriate `@tag value` lines that, when parsed, will
        recreate the data of this tag. If the tag is marked as hidden, an
        additional `@hide tag` will be appended.

        If `.present` is false, a simple `@tag` line is returned. This is
        because UnknownTag objects are intended to represent unexpected tags
        parsed out of a document. Their presence always reflects intent from the
        document's creator, so they should always show up in the header.

        Returns:
            A string of the header lines needed to create this tag, or an empty
            string if the present is false.
        """
        if not self.present:
            return "@{}".format(self.name)

        return super().to_header()<commit_msg>Inherit from flag instead of tag<commit_after>from .flag import Flag

class UnknownTag(Flag):
    """
    Defines a mult-value unrecognized tag object

    These are special tag objects that represent an unexpected or unknown tag.
    They are added automatically when attempting to access a tag that was not
    initialized.

    These tags cannot be required and will always be invalid in strict mode.
    """
    def __init__(self, name: str, *args, hidden: bool=False, limit: int=-1):
        """
        Create a new Tag object

        Args:
            hidden (bool): Whether this tag should be displayed in character
                listings. When present, a coresponding @hide tag will be
                generated by to_header.
            limit (int): Maximum number of values allowed in the tag. Passing a
                negative number allows an infinite number of values to be
                stored.
            values (list): Initial values to save
        """
        super().__init__(name, *args, required=False, hidden=hidden, limit=limit)
        self._present = True

    def __repr__(self):
        return "{}({}, {}, hidden={}, limit={})".format(
            type(self).__name__,
            self.name,
            *self.data,
            self.hidden,
            self.limit
        )

    def validate(self, strict=False):
        """
        Validate this tag's attributes

        Validations:
            * Required is incompatible with a limit of zero
            * (strict) If limit is non-negative, the total values must be <= limit
            * (strict) This tag is always invalid in strict mode

        Args:
            strict (bool): Whether to report non-critical errors and omissions

        Returns:
            True if this tag has no validation problems, false if not
        """
        if strict:
            self.problems.append("Unrecognized tag '{}'".format(self.name))
            if self.limit > -1 and len(self.data) > self.limit:
                self.problems.append("Too many values for tag '{}'. Limit of {}".format(self.name, self.limit))

        return self.valid
{'fraction_non_alphanumeric': 0.0786265745631857, 'fraction_numerical': 0.000609508329947176, 'mean_word_length': 2.0202453987730062, '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': '4102556', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1169, 'n_words': 531}