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

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

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

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)