Fixed Python 2/3 issues and flake syntax issues

This commit is contained in:
Syrus Akbary 2017-07-23 19:30:13 -07:00
parent f8561fa5c4
commit 6c4f4624e3
9 changed files with 23 additions and 15 deletions

View File

@ -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__

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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():

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)