<commit_before># -*- coding: utf-8 -*-
from collections import OrderedDict
import inspect


def _namespace(obj):
    module = obj.__module__ or __name__

    if hasattr(obj, '__qualname__'):
        name = obj.__qualname__
        return '.'.join((module, name))

    klass = getattr(obj, '__self__', None)

    if klass and not inspect.isclass(klass):
        klass = klass.__class__

    if not klass:
        klass = getattr(obj, 'im_class', None)

    if klass:
        name = klass.__name__ + '.' + obj.__name__
    else:
        name = obj.__name__

    return '.'.join((module, name))


def generic(obj, *args, **kwargs):

    _args = None
    _kwargs = None

    generic_key = _namespace(obj)

    if args:
        _args = '.'.join(map(str, args))
        generic_key = generic_key + '.' + _args

    if kwargs:
        kwargs = OrderedDict(sorted(kwargs.items(), key=lambda t: t[0]))

        _kwargs = '.'.join(
            ['_'.join(map(str, item)) for item in kwargs.items()]
        )

        generic_key = generic_key + '.' + _kwargs

    return generic_key<commit_msg>use string format to generate cache key<commit_after># -*- coding: utf-8 -*-
from collections import OrderedDict
import inspect


def _namespace(obj):
    module = obj.__module__ or __name__

    if hasattr(obj, '__qualname__'):
        name = obj.__qualname__
        return '.'.join((module, name))

    klass = getattr(obj, '__self__', None)

    if klass and not inspect.isclass(klass):
        klass = klass.__class__

    if not klass:
        klass = getattr(obj, 'im_class', None)

    if klass:
        name = '{}.{}'.format(
            klass.__name__,
            obj.__name__
        )
    else:
        name = obj.__name__

    return '.'.join((module, name))


def generic(obj, *args, **kwargs):

    _args = None
    _kwargs = None

    generic_key = _namespace(obj)

    if args:
        _args = '.'.join(map(str, args))
        generic_key = '{}.{}'.format(
            generic_key,
            _args
        )

    if kwargs:
        kwargs = OrderedDict(sorted(kwargs.items(), key=lambda t: t[0]))

        _kwargs = '.'.join(
            ['_'.join(map(str, item)) for item in kwargs.items()]
        )

        generic_key = '{}.{}'.format(
            generic_key,
            _kwargs
        )

    return generic_key
{'fraction_non_alphanumeric': 0.1334481274214378, 'fraction_numerical': 0.0017219113215669393, 'mean_word_length': 2.102803738317757, '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': '7082257', 'n_tokens_mistral': 746, 'n_tokens_neox': 739, 'n_words': 188}