mirror of
https://github.com/graphql-python/graphene.git
synced 2025-07-22 13:59:51 +03:00
Raise error when arguments conains only type annotations
This commit is contained in:
parent
2e87ebe5fc
commit
ed0cfa5e4a
|
@ -75,6 +75,10 @@ def to_arguments(args, extra_args=None):
|
|||
from .field import Field
|
||||
from .inputfield import InputField
|
||||
|
||||
if type(args) == dict and len(args) == 1 and '__annotations__' in args:
|
||||
raise ValueError(f"Arguments class doesn't have any field but has type annotations. "
|
||||
f"You probably used ':' instead of '=' in class definition")
|
||||
|
||||
if extra_args:
|
||||
extra_args = sorted(extra_args.items(), key=lambda f: f[1])
|
||||
else:
|
||||
|
|
|
@ -7,6 +7,8 @@ from ..field import Field
|
|||
from ..inputfield import InputField
|
||||
from ..scalars import String
|
||||
from ..structures import NonNull
|
||||
from ..mutation import Mutation
|
||||
from graphene.utils.props import props
|
||||
|
||||
|
||||
def test_argument():
|
||||
|
@ -74,3 +76,16 @@ def test_argument_with_lazy_partial_type():
|
|||
MyType = object()
|
||||
arg = Argument(partial(lambda: MyType))
|
||||
assert arg.type == MyType
|
||||
|
||||
|
||||
def test_arguments_raise_if_type_annotations():
|
||||
class Arguments:
|
||||
id: String()
|
||||
|
||||
with raises(ValueError) as exec_info:
|
||||
to_arguments(props(Arguments))
|
||||
|
||||
assert str(exec_info.value) == (
|
||||
f"Arguments class doesn't have any field but has type annotations. "
|
||||
f"You probably used ':' instead of '=' in class definition"
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user