Skip to content

Commit fcd17e0

Browse files
committed
More type annotations in TypeInfo
Corresponds to graphql/graphql-js@c3292db
1 parent a56477d commit fcd17e0

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

graphql/utilities/type_info.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from typing import Any, Callable, List, Optional, Union, cast
22

33
from ..error import INVALID
4-
from ..language import FieldNode, OperationType
4+
from ..language import (
5+
ArgumentNode, DirectiveNode, EnumValueNode, FieldNode, InlineFragmentNode,
6+
ListValueNode, Node, ObjectFieldNode, OperationDefinitionNode,
7+
OperationType, SelectionSetNode, VariableDefinitionNode)
58
from ..type import (
69
GraphQLArgument, GraphQLCompositeType, GraphQLDirective,
710
GraphQLEnumValue, GraphQLField, GraphQLInputType, GraphQLInterfaceType,
@@ -93,23 +96,23 @@ def get_argument(self):
9396
def get_enum_value(self):
9497
return self._enum_value
9598

96-
def enter(self, node):
99+
def enter(self, node: Node):
97100
method = getattr(self, 'enter_' + node.kind, None)
98101
if method:
99102
return method(node)
100103

101-
def leave(self, node):
104+
def leave(self, node: Node):
102105
method = getattr(self, 'leave_' + node.kind, None)
103106
if method:
104107
return method()
105108

106109
# noinspection PyUnusedLocal
107-
def enter_selection_set(self, node):
110+
def enter_selection_set(self, node: SelectionSetNode):
108111
named_type = get_named_type(self.get_type())
109112
self._parent_type_stack.append(
110113
named_type if is_composite_type(named_type) else None)
111114

112-
def enter_field(self, node):
115+
def enter_field(self, node: FieldNode):
113116
parent_type = self.get_parent_type()
114117
if parent_type:
115118
field_def = self._get_field_def(self._schema, parent_type, node)
@@ -120,10 +123,10 @@ def enter_field(self, node):
120123
self._type_stack.append(
121124
field_type if is_output_type(field_type) else None)
122125

123-
def enter_directive(self, node):
126+
def enter_directive(self, node: DirectiveNode):
124127
self._directive = self._schema.get_directive(node.name.value)
125128

126-
def enter_operation_definition(self, node):
129+
def enter_operation_definition(self, node: OperationDefinitionNode):
127130
if node.operation == OperationType.QUERY:
128131
type_ = self._schema.query_type
129132
elif node.operation == OperationType.MUTATION:
@@ -134,22 +137,24 @@ def enter_operation_definition(self, node):
134137
type_ = None
135138
self._type_stack.append(type_ if is_object_type(type_) else None)
136139

137-
def enter_inline_fragment(self, node):
140+
def enter_inline_fragment(self, node: InlineFragmentNode):
138141
type_condition_ast = node.type_condition
139142
output_type = type_from_ast(
140143
self._schema, type_condition_ast
141144
) if type_condition_ast else get_named_type(self.get_type())
142145
self._type_stack.append(
143-
output_type if is_output_type(output_type) else None)
146+
cast(GraphQLOutputType, output_type) if is_output_type(output_type)
147+
else None)
144148

145149
enter_fragment_definition = enter_inline_fragment
146150

147-
def enter_variable_definition(self, node):
151+
def enter_variable_definition(self, node: VariableDefinitionNode):
148152
input_type = type_from_ast(self._schema, node.type)
149153
self._input_type_stack.append(
150-
input_type if is_input_type(input_type) else None)
154+
cast(GraphQLInputType, input_type) if is_input_type(input_type)
155+
else None)
151156

152-
def enter_argument(self, node):
157+
def enter_argument(self, node: ArgumentNode):
153158
field_or_directive = self.get_directive() or self.get_field_def()
154159
if field_or_directive:
155160
arg_def = field_or_directive.args.get(node.name.value)
@@ -163,15 +168,15 @@ def enter_argument(self, node):
163168
arg_type if is_input_type(arg_type) else None)
164169

165170
# noinspection PyUnusedLocal
166-
def enter_list_value(self, node):
171+
def enter_list_value(self, node: ListValueNode):
167172
list_type = get_nullable_type(self.get_input_type())
168173
item_type = list_type.of_type if is_list_type(list_type) else list_type
169174
# List positions never have a default value.
170175
self._default_value_stack.append(INVALID)
171176
self._input_type_stack.append(
172177
item_type if is_input_type(item_type) else None)
173178

174-
def enter_object_field(self, node):
179+
def enter_object_field(self, node: ObjectFieldNode):
175180
object_type = get_named_type(self.get_input_type())
176181
if is_input_object_type(object_type):
177182
input_field = object_type.fields.get(node.name.value)
@@ -183,7 +188,7 @@ def enter_object_field(self, node):
183188
self._input_type_stack.append(
184189
input_field_type if is_input_type(input_field_type) else None)
185190

186-
def enter_enum_value(self, node):
191+
def enter_enum_value(self, node: EnumValueNode):
187192
enum_type = get_named_type(self.get_input_type())
188193
if is_enum_type(enum_type):
189194
enum_value = enum_type.values.get(node.value)

0 commit comments

Comments
 (0)