mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-08 23:50:38 +03:00
Fixed Python 2/3 issues and flake syntax issues
This commit is contained in:
parent
f8561fa5c4
commit
6c4f4624e3
|
@ -1,4 +1,5 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
import six
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
@ -9,3 +10,10 @@ try:
|
||||||
from inspect import signature
|
from inspect import signature
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from .signature import signature
|
from .signature import signature
|
||||||
|
|
||||||
|
if six.PY2:
|
||||||
|
def func_name(func):
|
||||||
|
return func.func_name
|
||||||
|
else:
|
||||||
|
def func_name(func):
|
||||||
|
return func.__name__
|
||||||
|
|
|
@ -60,9 +60,9 @@ class ClientIDMutation(Mutation):
|
||||||
('Cannot set client_mutation_id in the payload object {}'
|
('Cannot set client_mutation_id in the payload object {}'
|
||||||
).format(repr(payload)))
|
).format(repr(payload)))
|
||||||
return payload
|
return payload
|
||||||
|
|
||||||
result = cls.mutate_and_get_payload(input, context, info)
|
result = cls.mutate_and_get_payload(input, context, info)
|
||||||
if is_thenable(result):
|
if is_thenable(result):
|
||||||
return Promise.resolve(result).then(on_resolve)
|
return Promise.resolve(result).then(on_resolve)
|
||||||
|
|
||||||
return on_resolve(result)
|
return on_resolve(result)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class Context(object):
|
class Context(object):
|
||||||
def __init__(self, **params):
|
def __init__(self, **params):
|
||||||
for key, value in params.items():
|
for key, value in params.items():
|
||||||
setattr(self,key, value)
|
setattr(self, key, value)
|
||||||
|
|
|
@ -37,7 +37,7 @@ class InputObjectType(dict, UnmountedType, BaseType):
|
||||||
dict.__init__(self, *args, **kwargs)
|
dict.__init__(self, *args, **kwargs)
|
||||||
for key, value in self.items():
|
for key, value in self.items():
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_container(cls, data):
|
def create_container(cls, data):
|
||||||
return cls(data, _as_container=True)
|
return cls(data, _as_container=True)
|
||||||
|
|
|
@ -3,8 +3,8 @@ import pytest
|
||||||
from ..objecttype import ObjectType
|
from ..objecttype import ObjectType
|
||||||
from ..unmountedtype import UnmountedType
|
from ..unmountedtype import UnmountedType
|
||||||
from ..abstracttype import AbstractType
|
from ..abstracttype import AbstractType
|
||||||
|
from .. import abstracttype
|
||||||
from ..field import Field
|
from ..field import Field
|
||||||
from ...utils import deprecated
|
|
||||||
|
|
||||||
|
|
||||||
class MyType(ObjectType):
|
class MyType(ObjectType):
|
||||||
|
@ -18,12 +18,12 @@ class MyScalar(UnmountedType):
|
||||||
|
|
||||||
|
|
||||||
def test_abstract_objecttype_warn_deprecation(mocker):
|
def test_abstract_objecttype_warn_deprecation(mocker):
|
||||||
mocker.patch.object(deprecated, 'warn_deprecation')
|
mocker.patch.object(abstracttype, 'warn_deprecation')
|
||||||
|
|
||||||
class MyAbstractType(AbstractType):
|
class MyAbstractType(AbstractType):
|
||||||
field1 = MyScalar()
|
field1 = MyScalar()
|
||||||
|
|
||||||
deprecated.warn_deprecation.assert_called_once()
|
abstracttype.warn_deprecation.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
def test_generate_objecttype_inherit_abstracttype():
|
def test_generate_objecttype_inherit_abstracttype():
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import six
|
import six
|
||||||
from functools import wraps
|
from ..pyutils.compat import signature, func_name
|
||||||
from ..pyutils.compat import signature
|
|
||||||
|
|
||||||
from .deprecated import warn_deprecation
|
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}".'
|
'The key {key} is not a function parameter in the function "{func_name}".'
|
||||||
).format(
|
).format(
|
||||||
key=key,
|
key=key,
|
||||||
func_name=_func.func_name
|
func_name=func_name(_func)
|
||||||
)
|
)
|
||||||
|
|
||||||
func_annotations = getattr(_func, '__annotations__', None)
|
func_annotations = getattr(_func, '__annotations__', None)
|
||||||
|
@ -33,6 +32,6 @@ def annotate(_func=None, _trigger_warning=True, **annotations):
|
||||||
_func.__annotations__ = annotations
|
_func.__annotations__ = annotations
|
||||||
else:
|
else:
|
||||||
_func.__annotations__.update(annotations)
|
_func.__annotations__.update(annotations)
|
||||||
|
|
||||||
_func._is_annotated = True
|
_func._is_annotated = True
|
||||||
return _func
|
return _func
|
||||||
|
|
|
@ -4,7 +4,7 @@ from .resolver_from_annotations import resolver_from_annotations, is_wrapped_fro
|
||||||
def auto_resolver(func=None):
|
def auto_resolver(func=None):
|
||||||
annotations = getattr(func, '__annotations__', {})
|
annotations = getattr(func, '__annotations__', {})
|
||||||
is_annotated = getattr(func, '_is_annotated', False)
|
is_annotated = getattr(func, '_is_annotated', False)
|
||||||
|
|
||||||
if (annotations or is_annotated) and not is_wrapped_from_annotations(func):
|
if (annotations or is_annotated) and not is_wrapped_from_annotations(func):
|
||||||
# Is a Graphene 2.0 resolver function
|
# Is a Graphene 2.0 resolver function
|
||||||
return resolver_from_annotations(func)
|
return resolver_from_annotations(func)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from six import PY2
|
from six import PY2
|
||||||
from functools import wraps
|
|
||||||
from .annotate import annotate
|
from .annotate import annotate
|
||||||
from .deprecated import deprecated
|
from .deprecated import deprecated
|
||||||
|
|
||||||
|
@ -11,9 +10,11 @@ if PY2:
|
||||||
else:
|
else:
|
||||||
deprecation_reason = (
|
deprecation_reason = (
|
||||||
'The decorator @resolve_only_args is deprecated.\n'
|
'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)
|
@deprecated(deprecation_reason)
|
||||||
def resolve_only_args(func):
|
def resolve_only_args(func):
|
||||||
return annotate(func)
|
return annotate(func)
|
||||||
|
|
|
@ -37,7 +37,7 @@ def resolver_from_annotations(func):
|
||||||
else:
|
else:
|
||||||
def inner(root, args, context, info):
|
def inner(root, args, context, info):
|
||||||
return func(root, **args)
|
return func(root, **args)
|
||||||
|
|
||||||
inner._is_wrapped_from_annotations = True
|
inner._is_wrapped_from_annotations = True
|
||||||
return wraps(func)(inner)
|
return wraps(func)(inner)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user