diff --git a/graphene/pyutils/compat.py b/graphene/pyutils/compat.py index 68734a99..86452081 100644 --- a/graphene/pyutils/compat.py +++ b/graphene/pyutils/compat.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +import six try: from enum import Enum @@ -9,3 +10,10 @@ try: from inspect import signature except ImportError: from .signature import signature + +if six.PY2: + def func_name(func): + return func.func_name +else: + def func_name(func): + return func.__name__ diff --git a/graphene/relay/mutation.py b/graphene/relay/mutation.py index 1f8f80e5..fb57c275 100644 --- a/graphene/relay/mutation.py +++ b/graphene/relay/mutation.py @@ -60,9 +60,9 @@ class ClientIDMutation(Mutation): ('Cannot set client_mutation_id in the payload object {}' ).format(repr(payload))) return payload - + result = cls.mutate_and_get_payload(input, context, info) if is_thenable(result): return Promise.resolve(result).then(on_resolve) - + return on_resolve(result) diff --git a/graphene/types/context.py b/graphene/types/context.py index 4877ce13..bac2073c 100644 --- a/graphene/types/context.py +++ b/graphene/types/context.py @@ -1,4 +1,4 @@ class Context(object): def __init__(self, **params): for key, value in params.items(): - setattr(self,key, value) + setattr(self, key, value) diff --git a/graphene/types/inputobjecttype.py b/graphene/types/inputobjecttype.py index 19bb7c74..cf66065f 100644 --- a/graphene/types/inputobjecttype.py +++ b/graphene/types/inputobjecttype.py @@ -37,7 +37,7 @@ class InputObjectType(dict, UnmountedType, BaseType): dict.__init__(self, *args, **kwargs) for key, value in self.items(): setattr(self, key, value) - + @classmethod def create_container(cls, data): return cls(data, _as_container=True) diff --git a/graphene/types/tests/test_abstracttype.py b/graphene/types/tests/test_abstracttype.py index 44fc570d..b1bcaa3f 100644 --- a/graphene/types/tests/test_abstracttype.py +++ b/graphene/types/tests/test_abstracttype.py @@ -3,8 +3,8 @@ import pytest from ..objecttype import ObjectType from ..unmountedtype import UnmountedType from ..abstracttype import AbstractType +from .. import abstracttype from ..field import Field -from ...utils import deprecated class MyType(ObjectType): @@ -18,12 +18,12 @@ class MyScalar(UnmountedType): def test_abstract_objecttype_warn_deprecation(mocker): - mocker.patch.object(deprecated, 'warn_deprecation') + mocker.patch.object(abstracttype, 'warn_deprecation') class MyAbstractType(AbstractType): field1 = MyScalar() - deprecated.warn_deprecation.assert_called_once() + abstracttype.warn_deprecation.assert_called_once() def test_generate_objecttype_inherit_abstracttype(): diff --git a/graphene/utils/annotate.py b/graphene/utils/annotate.py index 5298e40b..b55c3d6c 100644 --- a/graphene/utils/annotate.py +++ b/graphene/utils/annotate.py @@ -1,6 +1,5 @@ import six -from functools import wraps -from ..pyutils.compat import signature +from ..pyutils.compat import signature, func_name from .deprecated import warn_deprecation @@ -25,7 +24,7 @@ def annotate(_func=None, _trigger_warning=True, **annotations): 'The key {key} is not a function parameter in the function "{func_name}".' ).format( key=key, - func_name=_func.func_name + func_name=func_name(_func) ) func_annotations = getattr(_func, '__annotations__', None) @@ -33,6 +32,6 @@ def annotate(_func=None, _trigger_warning=True, **annotations): _func.__annotations__ = annotations else: _func.__annotations__.update(annotations) - + _func._is_annotated = True return _func diff --git a/graphene/utils/auto_resolver.py b/graphene/utils/auto_resolver.py index dd551731..633c1a95 100644 --- a/graphene/utils/auto_resolver.py +++ b/graphene/utils/auto_resolver.py @@ -4,7 +4,7 @@ from .resolver_from_annotations import resolver_from_annotations, is_wrapped_fro def auto_resolver(func=None): annotations = getattr(func, '__annotations__', {}) is_annotated = getattr(func, '_is_annotated', False) - + if (annotations or is_annotated) and not is_wrapped_from_annotations(func): # Is a Graphene 2.0 resolver function return resolver_from_annotations(func) diff --git a/graphene/utils/resolve_only_args.py b/graphene/utils/resolve_only_args.py index 93a5a0fb..e30f1f03 100644 --- a/graphene/utils/resolve_only_args.py +++ b/graphene/utils/resolve_only_args.py @@ -1,5 +1,4 @@ from six import PY2 -from functools import wraps from .annotate import annotate from .deprecated import deprecated @@ -11,9 +10,11 @@ if PY2: else: deprecation_reason = ( 'The decorator @resolve_only_args is deprecated.\n' - 'Please use Python 3 type annotations instead. Read more: https://docs.python.org/3/library/typing.html' + 'Please use Python 3 type annotations instead. Read more: ' + 'https://docs.python.org/3/library/typing.html' ) + @deprecated(deprecation_reason) def resolve_only_args(func): return annotate(func) diff --git a/graphene/utils/resolver_from_annotations.py b/graphene/utils/resolver_from_annotations.py index 49aee652..79fb99de 100644 --- a/graphene/utils/resolver_from_annotations.py +++ b/graphene/utils/resolver_from_annotations.py @@ -37,7 +37,7 @@ def resolver_from_annotations(func): else: def inner(root, args, context, info): return func(root, **args) - + inner._is_wrapped_from_annotations = True return wraps(func)(inner)