Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions graphene/types/argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions graphene/types/tests/test_argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
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():
Expand Down Expand Up @@ -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"
)