<commit_before>from functools import partial

import six
from graphql.core.type import GraphQLObjectType

from graphene import signals

from .base import FieldsClassType, FieldsClassTypeMeta, FieldsOptions
from .uniontype import UnionType


def is_objecttype(cls):
    if not issubclass(cls, ObjectType):
        return False
    return not(cls._meta.abstract or cls._meta.interface)


class ObjectTypeOptions(FieldsOptions):

    def __init__(self, *args, **kwargs):
        super(ObjectTypeOptions, self).__init__(*args, **kwargs)
        self.interface = False
        self.interfaces = []


class ObjectTypeMeta(FieldsClassTypeMeta):

    def construct(cls, bases, attrs):
        cls = super(ObjectTypeMeta, cls).construct(bases, attrs)
        if not cls._meta.abstract:
            union_types = list(filter(is_objecttype, bases))
            if len(union_types) > 1:
                meta_attrs = dict(cls._meta.original_attrs, types=union_types)
                Meta = type('Meta', (object, ), meta_attrs)
                attrs['Meta'] = Meta
                attrs['__module__'] = cls.__module__
                attrs['__doc__'] = cls.__doc__
                return type(cls.__name__, (UnionType, ), attrs)
        return cls

    options_class = ObjectTypeOptions


class ObjectType(six.with_metaclass(ObjectTypeMeta, FieldsClassType)):

    class Meta:
        abstract = True

    def __getattr__(self, name):
        if name != '_root' and self._root:
            return getattr(self._root, name)

    def __init__(self, *args, **kwargs):
        signals.pre_init.send(self.__class__, args=args, kwargs=kwargs)
        self._root = kwargs.pop('_root', None)
        args_len = len(args)
        fields = self._meta.fields
        if args_len > len(fields):
            # Daft, but matches old exception sans the err msg.
            raise IndexError("Number of args exceeds number of fields")
        fields_iter = iter(fields)

        if not kwargs:
            for val, field in zip(args, fields_iter):
                setattr(self, field.attname, val)
        else:
            for val, field in zip(args, fields_iter):
                setattr(self, field.attname, val)
                kwargs.pop(field.attname, None)

        for field in fields_iter:
            try:
                val = kwargs.pop(field.attname)
                setattr(self, field.attname, val)
            except KeyError:
                pass

        if kwargs:
            for prop in list(kwargs):
                try:
                    if isinstance(getattr(self.__class__, prop), property):
                        setattr(self, prop, kwargs.pop(prop))
                except AttributeError:
                    pass
            if kwargs:<commit_msg>Fixed default in DjangoConnection<commit_after>from functools import partial

import six
from graphql.core.type import GraphQLObjectType

from graphene import signals

from .base import FieldsClassType, FieldsClassTypeMeta, FieldsOptions
from .uniontype import UnionType


def is_objecttype(cls):
    if not issubclass(cls, ObjectType):
        return False
    return not(cls._meta.abstract or cls._meta.interface)


class ObjectTypeOptions(FieldsOptions):

    def __init__(self, *args, **kwargs):
        super(ObjectTypeOptions, self).__init__(*args, **kwargs)
        self.interface = False
        self.interfaces = []


class ObjectTypeMeta(FieldsClassTypeMeta):

    def construct(cls, bases, attrs):
        cls = super(ObjectTypeMeta, cls).construct(bases, attrs)
        if not cls._meta.abstract:
            union_types = list(filter(is_objecttype, bases))
            if len(union_types) > 1:
                meta_attrs = dict(cls._meta.original_attrs, types=union_types)
                Meta = type('Meta', (object, ), meta_attrs)
                attrs['Meta'] = Meta
                attrs['__module__'] = cls.__module__
                attrs['__doc__'] = cls.__doc__
                return type(cls.__name__, (UnionType, ), attrs)
        return cls

    options_class = ObjectTypeOptions


class ObjectType(six.with_metaclass(ObjectTypeMeta, FieldsClassType)):
    _root = None

    class Meta:
        abstract = True

    def __getattr__(self, name):
        print self._root
        return getattr(self._root, name)

    def __init__(self, *args, **kwargs):
        self._root = kwargs.pop('_root', None)
        signals.pre_init.send(self.__class__, args=args, kwargs=kwargs)
        args_len = len(args)
        fields = self._meta.fields
        if args_len > len(fields):
            # Daft, but matches old exception sans the err msg.
            raise IndexError("Number of args exceeds number of fields")
        fields_iter = iter(fields)

        if not kwargs:
            for val, field in zip(args, fields_iter):
                setattr(self, field.attname, val)
        else:
            for val, field in zip(args, fields_iter):
                setattr(self, field.attname, val)
                kwargs.pop(field.attname, None)

        for field in fields_iter:
            try:
                val = kwargs.pop(field.attname)
                setattr(self, field.attname, val)
            except KeyError:
                pass

        if kwargs:
            for prop in list(kwargs):
                try:
                    if isinstance(getattr(self.__class__, prop), property):
                        setattr(self, prop, kwargs.pop(prop))
                except AttributeError:
                    pass
            if kwargs:
{'fraction_non_alphanumeric': 0.09033194268093597, 'fraction_numerical': 0.00036277888626881915, 'mean_word_length': 2.117015262860373, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2750054', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1491, 'n_words': 397}