<commit_before>import copy

from .base import BaseField


__all__ = ['StringField', 'ListField', 'DictField',
           'GroupsField', 'ExtrasField']


class StringField(BaseField):
    default = None

    def validate(self, instance, name, value):
        if value is None:
            if self.required:
                raise TypeError("Required field cannot be None")
            return None

        if not isinstance(value, basestring):
            raise TypeError("Invalid type for string field {0!r}: {1!r}"
                            .format(name, type(value)))

        return value

    def serialize(self, instance, name):
        return self.get(instance, name)


class BoolField(BaseField):
    default = False

    def validate(self, instance, name, value):
        super(BoolField, self).validate(instance, name, value)

        if value is False or value is None:
            return False

        if value is True:
            return True

        raise TypeError("Invalid type for boolean field {0!r}: {1!r}"
                        .format(name, type(value)))

    def serialize(self, instance, name):
        return self.get(instance, name)

class IntegerField(BaseField):
    default = False

    def validate(self, instance, name, value):
        if value is None:
            if self.required:
                raise TypeError("Required field cannot be None")
            return None

        if not isinstance(value, int):
            raise TypeError("Invalid type for integer field {0!r}: {1!r}"
                            .format(name, type(value)))

        return value


class MutableFieldMixin(object):
    def get(self, instance, name):<commit_msg>[#18] Base fields now using default implementation of serialize()<commit_after>import copy

from .base import BaseField


__all__ = ['StringField', 'ListField', 'DictField',
           'GroupsField', 'ExtrasField']


class StringField(BaseField):
    default = None

    def validate(self, instance, name, value):
        if value is None:
            if self.required:
                raise TypeError("Required field cannot be None")
            return None

        if not isinstance(value, basestring):
            raise TypeError("Invalid type for string field {0!r}: {1!r}"
                            .format(name, type(value)))

        return value


class BoolField(BaseField):
    default = False

    def validate(self, instance, name, value):
        if value is False or value is None:
            return False

        if value is True:
            return True

        raise TypeError("Invalid type for boolean field {0!r}: {1!r}"
                        .format(name, type(value)))


class IntegerField(BaseField):
    default = 0

    def validate(self, instance, name, value):
        if value is None:
            if self.required:
                raise TypeError("Required field cannot be None")
            return None

        if not isinstance(value, int):
            raise TypeError("Invalid type for integer field {0!r}: {1!r}"
                            .format(name, type(value)))

        return value


class MutableFieldMixin(object):
    def get(self, instance, name):
{'fraction_non_alphanumeric': 0.09399559886828042, 'fraction_numerical': 0.004715498270983967, 'mean_word_length': 2.1135029354207435, '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': '4207248', 'n_tokens_mistral': 845, 'n_tokens_neox': 803, 'n_words': 291}