<commit_before>from functools import partial
import random

from django.apps import apps
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.db.models.fields import NOT_PROVIDED

from faker import Factory as FakerFactory

from .compat import string_types
from .exceptions import ForeignKeyError
from .lazy import Lazy
from .utils import get_model_fields, language_to_locale
from .values import Evaluator


user_model = get_user_model()

locale = language_to_locale(settings.LANGUAGE_CODE)


class Empty(object):
    pass


class Factory(object):

    def __init__(self, fake=None):
        self.fake = fake or FakerFactory.create(locale)

    def _get_model(self, model):
        if isinstance(model, string_types):
            model = apps.get_model(*model.split('.'))
        return model

    def seed(self, seed, set_global=False):
        self.fake.seed(seed)
        if set_global:
            random.seed(seed)

    def blueprint(self, *args, **kwargs):
        from .blueprint import Blueprint
        return Blueprint(*args, **kwargs)

    def build_one(self, model, fields=None, pre_save=None, seed=None, make_fks=False, iteration=None):
        if fields is None:
            fields = {}

        if pre_save is None:
            pre_save = []

        if seed:
            fake = FakerFactory.create(locale)
            fake.seed(seed)
        else:
            fake = self.fake

        evaluator = Evaluator(fake, factory=self, iteration=iteration)

        model = self._get_model(model)
        instance = model()
        m2ms = {}
        lazies = []

        for field_name, model_field in get_model_fields(model):
            if field_name.endswith('_id') and model_field.is_relation:
                field_name = field_name.split('_id')[0]

            if isinstance(model_field, models.AutoField):
                continue

            if field_name not in fields and (model_field.blank or model_field.null or model_field.default != NOT_PROVIDED):
                continue

            if field_name not in fields and isinstance(model_field, models.ManyToManyField):
                continue

            if isinstance(model_field, models.ForeignKey):
                value = fields.get(field_name, Empty)<commit_msg>avoid mutating argument<commit_after>from functools import partial
import random

from django.apps import apps
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.db.models.fields import NOT_PROVIDED

from faker import Factory as FakerFactory

from .compat import string_types
from .exceptions import ForeignKeyError
from .lazy import Lazy
from .utils import get_model_fields, language_to_locale
from .values import Evaluator


user_model = get_user_model()

locale = language_to_locale(settings.LANGUAGE_CODE)


class Empty(object):
    pass


class Factory(object):

    def __init__(self, fake=None):
        self.fake = fake or FakerFactory.create(locale)

    def _get_model(self, model):
        if isinstance(model, string_types):
            model = apps.get_model(*model.split('.'))
        return model

    def seed(self, seed, set_global=False):
        self.fake.seed(seed)
        if set_global:
            random.seed(seed)

    def blueprint(self, *args, **kwargs):
        from .blueprint import Blueprint
        return Blueprint(*args, **kwargs)

    def build_one(self, model, fields=None, pre_save=None, seed=None, make_fks=False, iteration=None):
        if fields is None:
            fields = {}

        if pre_save is None:
            pre_save = []

        if seed:
            fake = FakerFactory.create(locale)
            fake.seed(seed)
        else:
            fake = self.fake

        evaluator = Evaluator(fake, factory=self, iteration=iteration)

        model = self._get_model(model)
        instance = model()
        m2ms = {}
        lazies = []

        for _field_name, model_field in get_model_fields(model):
            if _field_name.endswith('_id') and model_field.is_relation:
                field_name = _field_name.split('_id')[0]
            else:
                field_name = _field_name

            if isinstance(model_field, models.AutoField):
                continue

            if field_name not in fields and (model_field.blank or model_field.null or model_field.default != NOT_PROVIDED):
                continue

            if field_name not in fields and isinstance(model_field, models.ManyToManyField):
                continue

            if isinstance(model_field, models.ForeignKey):
                value = fields.get(field_name, Empty)
{'fraction_non_alphanumeric': 0.08066581306017925, 'fraction_numerical': 0.0008536064874093043, 'mean_word_length': 2.5588458618071375, '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': '6319602', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1301, 'n_words': 358}