<commit_before>from __future__ import unicode_literals

import six
from django import forms
from django.db import models
from django.db.models.query import QuerySet

from .registry import registry as default_registry
from .widgets import ChoiceWidget, MultipleChoiceWidget

__all__ = ['FieldBase', 'ChoiceField', 'MultipleChoiceField',
    'ModelChoiceField', 'ModelMultipleChoiceField', 'GenericModelChoiceField',
    'GenericModelMultipleChoiceField']


class FieldBase(object):
    def __init__(self, autocomplete=None, registry=None, widget=None,
            widget_js_attributes=None, autocomplete_js_attributes=None,
            extra_context=None, *args, **kwargs):

        self.autocomplete = self.get_autocomplete(autocomplete, registry,
                widget)

        widget = widget or self.widget
        if isinstance(widget, type):
            widget = widget(autocomplete, widget_js_attributes,
                    autocomplete_js_attributes, extra_context)
        kwargs['widget'] = widget

        # Does the subclass have ModelChoiceField or ModelMultipleChoiceField
        # as a base class?
        parents = type(self).__mro__
        if ((forms.ModelChoiceField in parents or
                forms.ModelMultipleChoiceField in parents) and
                isinstance(self.autocomplete.choices, QuerySet)):
            kwargs['queryset'] = self.autocomplete.choices

        super(FieldBase, self).__init__(*args, **kwargs)

    def get_autocomplete(self, autocomplete, registry, widget):
        if widget:
            # BC: maybe defining the autocomplete as a widget argument ?
            autocomplete = getattr(widget, 'autocomplete', None)

        registry = registry or default_registry
        return registry.get_autocomplete_from_arg(autocomplete)<commit_msg>Remove broken code<commit_after>from __future__ import unicode_literals

import six
from django import forms
from django.db import models
from django.db.models.query import QuerySet

from .registry import registry as default_registry
from .widgets import ChoiceWidget, MultipleChoiceWidget

__all__ = ['FieldBase', 'ChoiceField', 'MultipleChoiceField',
    'ModelChoiceField', 'ModelMultipleChoiceField', 'GenericModelChoiceField',
    'GenericModelMultipleChoiceField']


class FieldBase(object):
    def __init__(self, autocomplete=None, registry=None, widget=None,
            widget_js_attributes=None, autocomplete_js_attributes=None,
            extra_context=None, *args, **kwargs):

        self.autocomplete = self.get_autocomplete(autocomplete, registry,
                widget)

        widget = widget or self.widget
        if isinstance(widget, type):
            widget = widget(autocomplete, widget_js_attributes,
                    autocomplete_js_attributes, extra_context)
        kwargs['widget'] = widget

        # Does the subclass have ModelChoiceField or ModelMultipleChoiceField
        # as a base class?
        parents = type(self).__mro__
        if ((forms.ModelChoiceField in parents or
                forms.ModelMultipleChoiceField in parents) and
                isinstance(self.autocomplete.choices, QuerySet)):
            kwargs['queryset'] = self.autocomplete.choices

        super(FieldBase, self).__init__(*args, **kwargs)

    def get_autocomplete(self, autocomplete, registry, widget):
        registry = registry or default_registry
        return registry.get_autocomplete_from_arg(autocomplete)
{'fraction_non_alphanumeric': 0.07652022112307244, 'fraction_numerical': 0.0, 'mean_word_length': 3.3964194373401533, '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': '3193054', 'n_tokens_mistral': 903, 'n_tokens_neox': 845, 'n_words': 230}