Skip to content

Commit 183fd4a

Browse files
committed
Remove use of existential type in validation tests
Replicates graphql/graphql-js@b40291f
1 parent 583dd79 commit 183fd4a

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

tests/type/test_validation.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from functools import partial
2-
from typing import cast, List
2+
from typing import cast, List, Union
33

44
from pytest import mark, raises # type: ignore
55

@@ -14,7 +14,9 @@
1414
GraphQLInputObjectType,
1515
GraphQLInterfaceType,
1616
GraphQLList,
17+
GraphQLNamedType,
1718
GraphQLNonNull,
19+
GraphQLNullableType,
1820
GraphQLObjectType,
1921
GraphQLOutputType,
2022
GraphQLScalarType,
@@ -52,17 +54,18 @@
5254
)
5355

5456

55-
def with_modifiers(types: List) -> List:
56-
# noinspection PyTypeChecker
57+
def with_modifiers(
58+
types: List[GraphQLNamedType]
59+
) -> List[Union[GraphQLNamedType, GraphQLNonNull, GraphQLList]]:
5760
return (
58-
types
61+
cast(List[Union[GraphQLNamedType, GraphQLNonNull, GraphQLList]], types)
5962
+ [GraphQLList(t) for t in types]
60-
+ [GraphQLNonNull(t) for t in types]
63+
+ [GraphQLNonNull(cast(GraphQLNullableType, t)) for t in types]
6164
+ [GraphQLNonNull(GraphQLList(t)) for t in types]
6265
)
6366

6467

65-
output_types: List[GraphQLOutputType] = with_modifiers(
68+
output_types = with_modifiers(
6669
[
6770
GraphQLString,
6871
SomeScalarType,
@@ -73,15 +76,13 @@ def with_modifiers(types: List) -> List:
7376
]
7477
)
7578

76-
not_output_types: List[GraphQLInputType] = with_modifiers([SomeInputObjectType])
79+
not_output_types = with_modifiers([SomeInputObjectType])
7780

78-
input_types: List[GraphQLInputType] = with_modifiers(
81+
input_types = with_modifiers(
7982
[GraphQLString, SomeScalarType, SomeEnumType, SomeInputObjectType]
8083
)
8184

82-
not_input_types: List[GraphQLOutputType] = with_modifiers(
83-
[SomeObjectType, SomeUnionType, SomeInterfaceType]
84-
)
85+
not_input_types = with_modifiers([SomeObjectType, SomeUnionType, SomeInterfaceType])
8586

8687
parametrize_type = partial(
8788
mark.parametrize("type_", ids=lambda type_: type_.__class__.__name__)
@@ -892,6 +893,7 @@ def accepts_an_output_type_as_an_object_field_type(type_):
892893
def rejects_an_empty_object_field_type():
893894
# invalid schema cannot be built with Python
894895
with raises(TypeError) as exc_info:
896+
# noinspection PyTypeChecker
895897
_schema_with_object_field_of_type(None)
896898
msg = str(exc_info.value)
897899
assert msg == "Field type must be an output type."
@@ -1178,6 +1180,7 @@ def accepts_an_output_type_as_an_interface_field_type(type_):
11781180
def rejects_an_empty_interface_field_type():
11791181
# invalid schema cannot be built with Python
11801182
with raises(TypeError) as exc_info:
1183+
# noinspection PyTypeChecker
11811184
_schema_with_interface_field_of_type(None)
11821185
msg = str(exc_info.value)
11831186
assert msg == "Field type must be an output type."
@@ -1263,6 +1266,7 @@ def accepts_an_input_type_as_a_field_arg_type(type_):
12631266
def rejects_an_empty_field_arg_type():
12641267
# invalid schema cannot be built with Python
12651268
with raises(TypeError) as exc_info:
1269+
# noinspection PyTypeChecker
12661270
_schema_with_arg_of_type(None)
12671271
msg = str(exc_info.value)
12681272
assert msg == "Argument type must be a GraphQL input type."
@@ -1329,6 +1333,7 @@ def accepts_an_input_type_as_an_input_fieldtype(type_):
13291333
def rejects_an_empty_input_field_type():
13301334
# invalid schema cannot be built with Python
13311335
with raises(TypeError) as exc_info:
1336+
# noinspection PyTypeChecker
13321337
_schema_with_input_field_of_type(None)
13331338
msg = str(exc_info.value)
13341339
assert msg == "Input field type must be a GraphQL input type."

0 commit comments

Comments
 (0)