Added type consistency.

This commit is contained in:
Daniel Johnston 2017-05-05 14:27:46 -07:00
parent 7642644d82
commit 388253ede4
2 changed files with 19 additions and 1 deletions

View File

@ -4,6 +4,7 @@ from itertools import chain
from .mountedtype import MountedType from .mountedtype import MountedType
from .structures import NonNull from .structures import NonNull
from .dynamic import Dynamic from .dynamic import Dynamic
from .utils import get_type
class Argument(MountedType): class Argument(MountedType):
@ -15,10 +16,14 @@ class Argument(MountedType):
type = NonNull(type) type = NonNull(type)
self.name = name self.name = name
self.type = type self._type = type
self.default_value = default_value self.default_value = default_value
self.description = description self.description = description
@property
def type(self):
return get_type(self._type)
def __eq__(self, other): def __eq__(self, other):
return isinstance(other, Argument) and ( return isinstance(other, Argument) and (
self.name == other.name, self.name == other.name,

View File

@ -1,4 +1,5 @@
import pytest import pytest
from functools import partial
from ..argument import Argument, to_arguments from ..argument import Argument, to_arguments
from ..field import Field from ..field import Field
@ -61,3 +62,15 @@ def test_to_arguments_raises_if_inputfield():
to_arguments(args) to_arguments(args)
assert str(exc_info.value) == 'Expected arg_string to be Argument, but received InputField. Try using Argument(String).' assert str(exc_info.value) == 'Expected arg_string to be Argument, but received InputField. Try using Argument(String).'
def test_argument_with_lazy_type():
MyType = object()
arg = Field(lambda: MyType)
assert arg.type == MyType
def test_argument_with_lazy_partial_type():
MyType = object()
arg = Field(partial(lambda: MyType))
assert arg.type == MyType