<commit_before>"""
Model

model class is a convenient way to use schema, it's inspired by data class but
works differently, it's much simpler and easy to use.

define a base model:

    @modelclass
    class Model:
        # define common fields and methods here
        # __init__, __repr__ and __eq__ will auto created if not exists

or

    @modelclass(compiler=xxx)
    class Model:
        pass

define models:

    class User:
        id = T.int
        age = T.int.default(18)
        name = T.str

schema slice:

    Lite = User['id', 'name']

use the model:

    user = User(id=1, name='test')
    # convert model to dict
    asdict(user)
    # get fields
    fields(user)  # or fields(User)
    # get the schema
    T(user)  # or T(User)
"""
from .schema import Compiler, T, Schema
from ._exception import Invalid, mark_key


def modelclass(cls=None, *, compiler=None):
    if cls is not None:
        return _create_model_class(cls, compiler=compiler)
    def decorator(cls):
        return _create_model_class(cls, compiler=compiler)
    return decorator


def _extract_schemas(namespace):
    schemas = {}
    for k, v in namespace.items():<commit_msg>fix code style<commit_after>"""
Model

model class is a convenient way to use schema, it's inspired by data class but
works differently, it's much simpler and easy to use.

define a base model:

    @modelclass
    class Model:
        # define common fields and methods here
        # __init__, __repr__ and __eq__ will auto created if not exists

or

    @modelclass(compiler=xxx)
    class Model:
        pass

define models:

    class User:
        id = T.int
        age = T.int.default(18)
        name = T.str

schema slice:

    Lite = User['id', 'name']

use the model:

    user = User(id=1, name='test')
    # convert model to dict
    asdict(user)
    # get fields
    fields(user)  # or fields(User)
    # get the schema
    T(user)  # or T(User)
"""
from .schema import Compiler, T, Schema
from ._exception import Invalid, mark_key


def modelclass(cls=None, *, compiler=None):
    if cls is not None:
        return _create_model_class(cls, compiler=compiler)

    def decorator(cls):
        return _create_model_class(cls, compiler=compiler)

    return decorator


def _extract_schemas(namespace):
    schemas = {}
    for k, v in namespace.items():
{'fraction_non_alphanumeric': 0.09001285897985427, 'fraction_numerical': 0.002571795970852979, 'mean_word_length': 2.8075040783034257, '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': '4177673', 'n_tokens_mistral': 733, 'n_tokens_neox': 708, 'n_words': 257}