<commit_before>
__all__ = ('to_bool', 'ConfigPropertyList')

from kivy.properties import ConfigParserProperty
from re import compile, split
from functools import partial

to_list_pat = compile(', *')


def to_bool(val):
    '''
    Takes anything and converts it to a bool type.
    '''
    if val == 'False':
        return False
    return not not val


def ConfigPropertyList(val, section, key, config, val_type, **kwargs):
    def to_list(val):
        if isinstance(val, list):
            vals = val
        else:
            vals = split(to_list_pat, val.strip(' []()'))
        for i, v in enumerate(vals):
            vals[i] = val_type(v)
        return vals

    if not isinstance(val, list):
        val = [val]
    return ConfigParserProperty(val, section, key, config, val_type=to_list,
                                **kwargs)
<commit_msg>Add 2d list to ConfigProperty.<commit_after>
__all__ = ('to_bool', 'ConfigPropertyList')

from kivy.properties import ConfigParserProperty
from re import compile, split

to_list_pat = compile('(?:, *)?\\n?')


def to_bool(val):
    '''
    Takes anything and converts it to a bool type.
    '''
    if val == 'False':
        return False
    return not not val


def ConfigPropertyList(val, section, key, config, val_type, inner_list=False,
                       **kwargs):
    ''' Accepts either a list of a string. Nothing else.
    '''
    def to_list(val):
        if isinstance(val, list):
            vals = list(val)
        else:
            vals = split(to_list_pat, val.strip(' []()'))
        for i, v in enumerate(vals):
            vals[i] = val_type(v)
        return vals

    def to_2d_list(val):
        if isinstance(val, list):
            vals = list(val)
        else:
            vals = [split(to_list_pat, line.strip(' []()'))
                    for line in val.strip(' []()').splitlines()]
        for i, line in enumerate(vals):
            for j, v in enumerate(line):
                vals[i][j] = val_type(v)
        return vals

    if not isinstance(val, list):
        val = [[val]] if inner_list else [val]
    v_type = to_2d_list if inner_list else to_list
    return ConfigParserProperty(val, section, key, config, val_type=v_type,
                                **kwargs)

{'fraction_non_alphanumeric': 0.11699779249448124, 'fraction_numerical': 0.0013245033112582781, 'mean_word_length': 2.2096317280453257, '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': '3653200', 'n_tokens_mistral': 704, 'n_tokens_neox': 680, 'n_words': 209}