<commit_before>from django.db.models.signals import post_init


def fixup_instance(sender, **kwargs):
    instance = kwargs['instance']
    instance.attrs._instance = instance


def fix_model_for_attributes(cls):
    post_init.connect(fixup_instance, sender=cls)
    return cls<commit_msg>Generalise instance assignment for fields<commit_after>from django.db.models.signals import post_init

from .fields import JSONAttributes


def fixup_instance(sender, **kwargs):
    instance = kwargs['instance']
    for k, v in instance.__dict__.items():
        if isinstance(v, JSONAttributes):
            v._instance = instance


def fix_model_for_attributes(cls):
    post_init.connect(fixup_instance, sender=cls)
    return cls
{'fraction_non_alphanumeric': 0.09141274238227147, 'fraction_numerical': 0.0, 'mean_word_length': 4.6484375, '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': '5413095', 'n_tokens_mistral': 209, 'n_tokens_neox': 208, 'n_words': 49}