Skip to content

Commit 65cb3e5

Browse files
committed
convert type comments to annotations
1 parent 34a2d1e commit 65cb3e5

File tree

7 files changed

+45
-60
lines changed

7 files changed

+45
-60
lines changed

graphene_tornado/apollo_tooling/transforms.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
from graphene_tornado.apollo_tooling.seperate_operations import separate_operations
1414

1515

16-
def hide_literals(ast):
17-
# type: (Document) -> Document
16+
def hide_literals(ast: Document) -> Document:
1817
"""
1918
Replace numeric, string, list, and object literals with "empty"
2019
values. Leaves enums alone (since there's no consistent "zero" enum). This
@@ -27,8 +26,7 @@ def hide_literals(ast):
2726
return ast
2827

2928

30-
def hide_string_and_numeric_literals(ast):
31-
# type: (Document) -> Document
29+
def hide_string_and_numeric_literals(ast: Document) -> Document:
3230
"""
3331
In the same spirit as the similarly named `hideLiterals` function, only
3432
hide string and numeric literals.
@@ -37,8 +35,7 @@ def hide_string_and_numeric_literals(ast):
3735
return ast
3836

3937

40-
def drop_unused_definitions(ast, operation_name):
41-
# type: (Document, str) -> Document
38+
def drop_unused_definitions(ast: Document, operation_name: str) -> Document:
4239
"""
4340
A GraphQL query may contain multiple named operations, with the operation to
4441
use specified separately by the client. This transformation drops unused
@@ -52,8 +49,7 @@ def drop_unused_definitions(ast, operation_name):
5249
return separated
5350

5451

55-
def sort_ast(ast):
56-
# type: (Document) -> Document
52+
def sort_ast(ast: Document) -> Document:
5753
"""
5854
sortAST sorts most multi-child nodes alphabetically. Using this as part of
5955
your signature calculation function may make it easier to tell the difference
@@ -65,8 +61,7 @@ def sort_ast(ast):
6561
return ast
6662

6763

68-
def remove_aliases(ast):
69-
# type: (Document) -> Document
64+
def remove_aliases(ast: Document) -> Document:
7065
"""
7166
removeAliases gets rid of GraphQL aliases, a feature by which you can tell a
7267
server to return a field's data under a different name from the field
@@ -77,8 +72,7 @@ def remove_aliases(ast):
7772
return ast
7873

7974

80-
def print_with_reduced_whitespace(ast):
81-
# type: (Document) -> str
75+
def print_with_reduced_whitespace(ast: Document) -> str:
8276
"""
8377
Like the graphql-js print function, but deleting whitespace wherever
8478
feasible. Specifically, all whitespace (outside of string literals) is

graphene_tornado/ext/apollo_engine_reporting/engine_agent.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@
5454
EngineReportingOptions.__new__.__defaults__ = (None,) * len(EngineReportingOptions._fields)
5555

5656

57-
def _serialize(message):
58-
# type: (Message) -> bytes
57+
def _serialize(message: Message) -> bytes:
5958
out = BytesIO() if six.PY3 else StringIO()
6059
with gzip.GzipFile(fileobj=out, mode="w") as f:
6160
f.write(message.SerializeToString())
@@ -71,7 +70,7 @@ def _get_trace_signature(operation_name, document_ast, query_string):
7170

7271
class EngineReportingAgent:
7372

74-
def __init__(self, options, schema_hash): # type: (EngineReportingOptions, str) -> None
73+
def __init__(self, options: EngineReportingOptions, schema_hash: str) -> None:
7574
self.options = options
7675
self.api_key = options.api_key or os.getenv('ENGINE_API_KEY', None)
7776

@@ -176,6 +175,6 @@ async def send_report_and_report_errors(self):
176175

177176
def reset_report(self):
178177
self.report = FullTracesReport(header=self.report_header)
179-
self.report_size = 0 # type: int
178+
self.report_size: int = 0
180179

181180

graphene_tornado/ext/apollo_engine_reporting/engine_extension.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
])
2525

2626

27-
def generate_client_info(request):
28-
# type: (HTTPServerRequest) -> ClientInfo
27+
def generate_client_info(request: HTTPServerRequest) -> ClientInfo:
2928
return ClientInfo(
3029
request.headers.get(CLIENT_NAME_HEADER, ''),
3130
request.headers.get(CLIENT_REFERENCE_HEADER_KEY, ''),
@@ -45,7 +44,7 @@ def now_ns():
4544

4645
class EngineReportingExtension(GraphQLExtension):
4746

48-
def __init__(self, options, add_trace): # type: (EngineReportingOptions, Callable) -> None
47+
def __init__(self, options: EngineReportingOptions, add_trace: Callable) -> None:
4948
if add_trace is None:
5049
raise ValueError('add_trace must be defined')
5150

graphene_tornado/ext/apollo_engine_reporting/schema_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
from json_stable_stringify_python import stringify
99

1010

11-
def generate_schema_hash(schema):
12-
# type: (Schema) -> str
11+
def generate_schema_hash(schema: Schema) -> str:
1312
"""
1413
Generates a stable hash of the current schema using an introspection query.
1514
"""

graphene_tornado/extension_stack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def instantiate_extensions(extensions):
1818
class GraphQLExtensionStack(GraphQLExtension):
1919

2020
def __init__(self,
21-
extensions=None # type: List[Union[Callable[[], GraphQLExtension], GraphQLExtension]]
21+
extensions: List[Union[Callable[[], GraphQLExtension], GraphQLExtension]] = None
2222
):
23-
self.extensions = list(instantiate_extensions(extensions)) # type: List[GraphQLExtension]
23+
self.extensions: List[GraphQLExtension] = list(instantiate_extensions(extensions))
2424

2525
async def request_started(self, request, query_string, parsed_query, operation_name, variables, context, request_context):
2626
on_end = await self._handle_did_start('request_started', request, query_string, parsed_query, operation_name,

graphene_tornado/graphql_extension.py

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,48 @@ class GraphQLExtension:
2222

2323
@abstractmethod
2424
def request_started(self,
25-
request, # type: HTTPServerRequest
26-
query_string, # type: Optional[str],
27-
parsed_query, # type: Optional[Document]
28-
operation_name, # type: Optional[str]
29-
variables, # type: Optional[dict[str, Any]]
30-
context, # type: Any
31-
request_context # type: Any
32-
):
33-
# type: (...) -> EndHandler
25+
request: HTTPServerRequest,
26+
query_string: Optional[str],,
27+
parsed_query: Optional[Document],
28+
operation_name: Optional[str],
29+
variables: Optional[dict[str, Any]],
30+
context: Any,
31+
request_context: Any
32+
) -> EndHandler:
3433
pass
3534

3635
@abstractmethod
37-
def parsing_started(self, query_string): # type: (str) -> EndHandler
36+
def parsing_started(self, query_string: str) -> EndHandler:
3837
pass
3938

4039
@abstractmethod
41-
def validation_started(self):
42-
# type: () -> EndHandler
40+
def validation_started(self) -> EndHandler:
4341
pass
4442

4543
@abstractmethod
4644
def execution_started(self,
47-
schema, # type: GraphQLSchema
48-
document, # type: Document
49-
root, # type: Any
50-
context, # type: Optional[Any]
51-
variables, # type: Optional[Any]
52-
operation_name, # type: Optional[str]
53-
request_context # type: Dict[Any, Any]
54-
):
55-
# type: (...) -> EndHandler
45+
schema: GraphQLSchema,
46+
document: Document,
47+
root: Any,
48+
context: Optional[Any],
49+
variables: Optional[Any],
50+
operation_name: Optional[str],
51+
request_context: Dict[Any, Any]
52+
) -> EndHandler:
5653
pass
5754

5855
@abstractmethod
59-
def will_resolve_field(self, root, info, **args):
60-
# type: (...) -> EndHandler
56+
def will_resolve_field(self, root, info, **args) -> EndHandler:
6157
pass
6258

6359
@abstractmethod
6460
def will_send_response(self,
65-
response, # type: Any
66-
context, # type: Any
67-
):
68-
# type: (...) -> EndHandler
61+
response: Any,
62+
context: Any,
63+
) -> EndHandler:
6964
pass
7065

71-
def as_middleware(self):
72-
# type: () -> Callable
66+
def as_middleware(self) -> Callable:
7367
"""
7468
Adapter for using the stack as middleware so that the will_resolve_field function
7569
is invoked like normal middleware

graphene_tornado/tornado_graphql_handler.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ class TornadoGraphQLHandler(web.RequestHandler):
5353
request_context = {}
5454

5555
def initialize(self,
56-
schema=None, # type:
56+
schema=None,
5757
executor=None,
58-
middleware=None, # type: Optional[Any]
59-
root_value=None, # type: Any
60-
graphiql=False, # type: bool
61-
pretty=False, # type: bool
62-
batch=False, # type: bool
63-
backend=None, # type: GraphQLBackend
64-
extensions=None # type: List[Union[Callable[[], GraphQLExtension], GraphQLExtension]]
58+
middleware: Optional[Any] = None,
59+
root_value: Any = None,
60+
graphiql: bool = False,
61+
pretty: bool = False,
62+
batch: bool = False,
63+
backend: GraphQLBackend = None,
64+
extensions: List[Union[Callable[[], GraphQLExtension], GraphQLExtension]] = None
6565
):
6666
super(TornadoGraphQLHandler, self).initialize()
6767

0 commit comments

Comments
 (0)