<commit_before>"""
Meta tools for class construction.
"""
from collections import OrderedDict
import inspect
import ctypes

def reload_locals(frame):
    ctypes.pythonapi.PyFrame_LocalsToFast(ctypes.py_object(frame), ctypes.c_int(1))

class MetaDict(OrderedDict):
    def __init__(self, setitem_handler):
        self.setitem_handler = setitem_handler
        self.classdict = ClassDict(self)
        super().__init__()

    def __setitem__(self, key, value):
        ret = self.setitem_handler(key, value, self.classdict)
        if ret is False:
            return
        super().__setitem__(key, value)

class ClassDict:
    """ simple obj to limit interface to MetaDict """
    def __init__(self, dct):
        self.dct = dct

    def __setitem__(self, key, value):
        super(MetaDict, self.dct).__setitem__(key, value)

    def __getitem__(self, key):
        return self.dct[key]

    def __contains__(self, key):
        return key in self.dct

    def __delitem__(self, key):
        del self.dct[key]

    def keys(self):
        return self.dct.keys()

class MetaMeta(type):
    @classmethod
    def __prepare__(mcl, name, bases):
        mdict = MetaDict(mcl.setitem_handler)
        return mdict

    def setitem_handler(key, value, scope):
        # raise NotImplementedError?
        pass

def mro(dct, bases, name):
    class_dicts = [base.__dict__ for base in bases] + [dct]
    for cdict in class_dicts:
        if name in cdict:
            return cdict[name]<commit_msg>Added proper copying for MetaDict<commit_after>"""
Meta tools for class construction.
"""
from collections import OrderedDict
import inspect
import ctypes

def reload_locals(frame):
    ctypes.pythonapi.PyFrame_LocalsToFast(ctypes.py_object(frame), ctypes.c_int(1))

class MetaDict(OrderedDict):
    def __init__(self, setitem_handler, *args, **kwargs):
        self.setitem_handler = setitem_handler
        self.classdict = ClassDict(self)
        super().__init__(*args, **kwargs)

    def __setitem__(self, key, value):
        super().__setitem__(key, value)

    def copy(self):
        return self.__class__(self.setitem_handler, self)


class ClassDict:
    """ simple obj to limit interface to MetaDict """
    def __init__(self, dct):
        self.dct = dct

    def __setitem__(self, key, value):
        super(MetaDict, self.dct).__setitem__(key, value)

    def __getitem__(self, key):
        return self.dct[key]

    def __contains__(self, key):
        return key in self.dct

    def __delitem__(self, key):
        del self.dct[key]

    def keys(self):
        return self.dct.keys()

class MetaMeta(type):
    @classmethod
    def __prepare__(mcl, name, bases):
        mdict = MetaDict(mcl.setitem_handler)
        return mdict

    def setitem_handler(key, value, scope):
        return True

def mro(dct, bases, name):
    class_dicts = [base.__dict__ for base in bases] + [dct]
    for cdict in class_dicts:
        if name in cdict:
            return cdict[name]
{'fraction_non_alphanumeric': 0.10224606101240362, 'fraction_numerical': 0.0006704659738518271, 'mean_word_length': 2.9628154050464808, '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': '190295', 'n_tokens_mistral': 962, 'n_tokens_neox': 946, 'n_words': 249}