From b58269ce7201d31655c17fb2c66c1cce8b348969 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Mon, 5 Oct 2015 22:30:05 -0700 Subject: [PATCH] Improved Python3 integration --- graphene/contrib/django/views.py | 2 +- graphene/core/fields.py | 5 +++-- graphene/core/types.py | 4 ++-- tests/contrib_django/test_views.py | 1 - 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/graphene/contrib/django/views.py b/graphene/contrib/django/views.py index f17d550b..9e5d6505 100644 --- a/graphene/contrib/django/views.py +++ b/graphene/contrib/django/views.py @@ -38,7 +38,7 @@ class GraphQLView(View): try: result = self.schema.execute(query, root=object()) data = self.format_result(result) - except Exception, e: + except Exception as e: if settings.DEBUG: raise e return self.response_errors(e) diff --git a/graphene/core/fields.py b/graphene/core/fields.py index f3a905d4..02263ad2 100644 --- a/graphene/core/fields.py +++ b/graphene/core/fields.py @@ -1,4 +1,5 @@ import inspect +import six from graphql.core.type import ( GraphQLField, GraphQLList, @@ -53,7 +54,7 @@ class Field(object): return field_type.get_object_type(schema) if _is_class and issubclass(field_type, BaseObjectType): return field_type - elif isinstance(field_type, basestring): + elif isinstance(field_type, six.string_types): if field_type == 'self': return self.object_type else: @@ -84,7 +85,7 @@ class Field(object): 'Field could not be constructed in a non graphene.Type or graphene.Interface') extra_args = self.extra_args.copy() - for arg_name, arg_value in extra_args.items(): + for arg_name, arg_value in self.extra_args.items(): if isinstance(arg_value, GraphQLArgument): self.args[arg_name] = arg_value del extra_args[arg_name] diff --git a/graphene/core/types.py b/graphene/core/types.py index a646f37b..89075b94 100644 --- a/graphene/core/types.py +++ b/graphene/core/types.py @@ -103,9 +103,9 @@ class BaseObjectType(object): return None elif type(instance) is cls: instance = instance.instance - return super(BaseObjectType, cls).__new__(cls, instance, *args, **kwargs) + return super(BaseObjectType, cls).__new__(cls, *args, **kwargs) - def __init__(self, instance=None): + def __init__(self, instance): signals.pre_init.send(self.__class__, instance=instance) self.instance = instance signals.post_init.send(self.__class__, instance=self) diff --git a/tests/contrib_django/test_views.py b/tests/contrib_django/test_views.py index bfd1efc3..f8ab5b20 100644 --- a/tests/contrib_django/test_views.py +++ b/tests/contrib_django/test_views.py @@ -33,7 +33,6 @@ def test_client_get_no_query(settings, client): def test_client_post_no_query(settings, client): settings.ROOT_URLCONF = 'tests.contrib_django.test_urls' response = client.post('/graphql', {}) - print response.content json_response = format_response(response) assert json_response == {'errors': [{'message': 'Must provide query string.'}]}