<commit_before>"""The fundamental *Ook* base data types for creation of derived child classes.

Usage
------

The **object_type** module allows for the construction of **Ook** data types.
An example data type definition would be constructed as::


    class MyType(BaseType):
        OOK_SCHEMA = SchemaType({
            'some_property': PropertyType({
                'type': 'int',
                'required': True,
            }),
            'other_property': PropertyType({
                'type': 'str',
                'required': False,
                'enum': {'Enum1', 'Enum2', 'Enum3'}
            }),
        })

    my_object = MyType()
    my_object.some_property = 7
    # or
    my_object['some_property'] = 7

Classes
--------
"""


class _CoreType(dict):
    """The root type of *Ook* types.

    **_CoreType** ensures that *Ook* objects can be access by either dict key
    or object attribute.

    :Example:
    >>> some_object = _CoreType({'key1': 'value1'})
    >>> assert some_object.key1 == 'value1'
    >>> assert some_object['key1'] == 'value1'
    >>> some_object.key2 = 'value2'
    >>> assert some_object['key2'] == 'value2'
    >>> some_object['key3'] = 'value3'
    >>> assert some_object.key3 == 'value3'
    """

    def __init__(self, *args, **kwargs):
        """**_CoreType** initialized as a `dict` type.

        :param args: Args to be passed to `dict` parent class.
        :type args: list
        :param kwargs: Named args to be passed to `dict` parent class.
        :type kwargs: dict

        Initializes the accessor behavior to allow for property access as
        dict key or object
        attribute.
        """
        # noinspection PyTypeChecker
        dict.__init__(self, *args, **kwargs)
        self.__dict__ = self


class SchemaType(_CoreType):
    """The type definition for a schema object.

    The **SchemaType** contains a dictionary of property field names and the
    corresponding **PropertySchema** definition.

    Example SchemaType representation::

        SchemaType({
          'some_property': PropertySchema({
                'type': 'str',
                'required': True
            })
        })
    """
    pass


class BaseType(_CoreType):
    """BaseType provides the **Ook** schema interface.

    The **BaseType** provides the schema management functionality to a
    derived **Ook** type instance.
    """

    # : The Ook schama pointer.
    OOK_SCHEMA = SchemaType()

    @classmethod
    def get_schema(cls):
        """Returns the **SchemaType** instance for a given **Ook** type.

        :return: The schema metadata definition for the BaseType derived
            child type.
        :rtype: ook.object_type.SchemaType.
        """
        return cls.OOK_SCHEMA


class PropertySchema(BaseType):
    """The object type for representing Property schema definitions.

    *Property Schema Settings*:

        *type*
            datetime*, date*, time*, str, int, float, bool, dict, set, list,
            none. Defaults to
            None.
        *required*
            True|False. Defaults False.
        *min*
            float. Defaults to None.
        *max*
            float. Defaults to None.
        *regex*
            string. Defaults to None.
        *item_type*
            datetime*, date*, time*, str, int, float, bool, dict, set, list,
            none. Default to None.
        *tem_min*
            float. Defaults to None.
        *item_max*
            float, Defaults to None.
    """
    # : todo: Add support for datetime, date & time
    OOK_SCHEMA = BaseType(
        {
            'type': BaseType(
                {
                    'type': 'str',
                    'required': False,
                    'enum': {
                        'bool',
                        'dict',
                        'float',
                        'int',
                        'list',
                        'set',
                        'str',
                    }
                }),
            'required': BaseType(
                {
                    'type': 'bool',
                    'required': False,
                }),
            'enum': BaseType(
                {
                    'type': 'set',
                    'required': False,
                }),
            'min': BaseType(
                {
                    'type': float,
                    'required': False,
                }),
            'max': BaseType(
                {
                    'type': float,
                    'required': False,
                }),
            'regex': BaseType(
                {
                    'type': 'str',
                    'required': False,
                    'min': 1,
                }),
            'item_type': {
                'type': 'str',
                'required': False,
                'enum': {
                    'bool',
                    'dict',
                    'float',
                    'int',
                    'list',
                    'set',
                    'str',
                }},
            'item_min': BaseType(
                {
                    'type': float,
                    'required': False,
                }),
            'item_max': BaseType(
                {
                    'type': float,
                    'required': False,
                }),
        }
    )

<commit_msg>PEP8 fixes.<commit_after>"""The fundamental *Ook* base data types for creation of derived child classes.

Usage
------

The **object_type** module allows for the construction of **Ook** data types.
An example data type definition would be constructed as::


    class MyType(BaseType):
        OOK_SCHEMA = SchemaType({
            'some_property': PropertyType({
                'type': 'int',
                'required': True,
            }),
            'other_property': PropertyType({
                'type': 'str',
                'required': False,
                'enum': {'Enum1', 'Enum2', 'Enum3'}
            }),
        })

    my_object = MyType()
    my_object.some_property = 7
    # or
    my_object['some_property'] = 7

Classes
--------
"""


class _CoreType(dict):
    """The root type of *Ook* types.

    **_CoreType** ensures that *Ook* objects can be access by either dict key
    or object attribute.

    :Example:
    >>> some_object = _CoreType({'key1': 'value1'})
    >>> assert some_object.key1 == 'value1'
    >>> assert some_object['key1'] == 'value1'
    >>> some_object.key2 = 'value2'
    >>> assert some_object['key2'] == 'value2'
    >>> some_object['key3'] = 'value3'
    >>> assert some_object.key3 == 'value3'
    """

    def __init__(self, *args, **kwargs):
        """**_CoreType** initialized as a `dict` type.

        :param args: Args to be passed to `dict` parent class.
        :type args: list
        :param kwargs: Named args to be passed to `dict` parent class.
        :type kwargs: dict

        Initializes the accessor behavior to allow for property access as
        dict key or object
        attribute.
        """
        # noinspection PyTypeChecker
        dict.__init__(self, *args, **kwargs)
        self.__dict__ = self


class SchemaType(_CoreType):
    """The type definition for a schema object.

    The **SchemaType** contains a dictionary of property field names and the
    corresponding **PropertySchema** definition.

    Example SchemaType representation::

        SchemaType({
          'some_property': PropertySchema({
                'type': 'str',
                'required': True
            })
        })
    """
    pass


class BaseType(_CoreType):
    """BaseType provides the **Ook** schema interface.

    The **BaseType** provides the schema management functionality to a
    derived **Ook** type instance.
    """

    # : The Ook schama pointer.
    OOK_SCHEMA = SchemaType()

    @classmethod
    def get_schema(cls):
        """Returns the **SchemaType** instance for a given **Ook** type.

        :return: The schema metadata definition for the BaseType derived
            child type.
        :rtype: ook.object_type.SchemaType.
        """
        return cls.OOK_SCHEMA


class PropertySchema(BaseType):
    """The object type for representing Property schema definitions.

    *Property Schema Settings*:

        *type*
            datetime*, date*, time*, str, int, float, bool, dict, set, list,
            none. Defaults to
            None.
        *required*
            True|False. Defaults False.
        *min*
            float. Defaults to None.
        *max*
            float. Defaults to None.
        *regex*
            string. Defaults to None.
        *item_type*
            datetime*, date*, time*, str, int, float, bool, dict, set, list,
            none. Default to None.
        *tem_min*
            float. Defaults to None.
        *item_max*
            float, Defaults to None.
    """
    # : todo: Add support for datetime, date & time
    OOK_SCHEMA = BaseType(
        {
            'type': BaseType(
                {
                    'type': 'str',
                    'required': False,
                    'enum': {
                        'bool',
                        'dict',
                        'float',
                        'int',
                        'list',
                        'set',
                        'str',
                    }
                }),
            'required': BaseType(
                {
                    'type': 'bool',
                    'required': False,
                }),
            'enum': BaseType(
                {
                    'type': 'set',
                    'required': False,
                }),
            'min': BaseType(
                {
                    'type': float,
                    'required': False,
                }),
            'max': BaseType(
                {
                    'type': float,
                    'required': False,
                }),
            'regex': BaseType(
                {
                    'type': 'str',
                    'required': False,
                    'min': 1,
                }),
            'item_type': {
                'type': 'str',
                'required': False,
                'enum': {
                    'bool',
                    'dict',
                    'float',
                    'int',
                    'list',
                    'set',
                    'str',
                }},
            'item_min': BaseType(
                {
                    'type': float,
                    'required': False,
                }),
            'item_max': BaseType(
                {
                    'type': float,
                    'required': False,
                }),
        }
    )
{'fraction_non_alphanumeric': 0.11655249027957786, 'fraction_numerical': 0.003795593408628032, 'mean_word_length': 1.2548528490920476, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, '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': '1732105', 'n_tokens_mistral': 2845, 'n_tokens_neox': 2673, 'n_words': 807}