Skip to content

Commit ce5a7b9

Browse files
style: adjust styles to pass hatch run check
1 parent 103278b commit ce5a7b9

36 files changed

+205
-170
lines changed

.git-blame-ignore-revs

Whitespace-only changes.

ariadne/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515
from .graphql import graphql, graphql_sync, subscribe
1616
from .inputs import InputType
17-
from .interfaces import InterfaceType, type_implements_interface
17+
from .interfaces import InterfaceType
1818
from .load_schema import load_schema_from_path
1919
from .objects import MutationType, ObjectType, QueryType
2020
from .resolvers import (
@@ -35,6 +35,7 @@
3535
convert_camel_case_to_snake,
3636
convert_kwargs_to_snake_case,
3737
gql,
38+
type_implements_interface,
3839
unwrap_graphql_error,
3940
)
4041

ariadne/asgi/handlers/graphql_transport_ws.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ async def observe_async_results(
525525
}
526526
)
527527
except asyncio.CancelledError: # pylint: disable=W0706
528-
# if asyncio Task is cancelled then CancelledError
528+
# if asyncio Task is cancelled then CancelledError
529529
# is thrown in the coroutine
530530
raise
531531
except Exception as error:

ariadne/contrib/sse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from .. import format_error
3131
from ..asgi.handlers import GraphQLHTTPHandler
3232
from ..exceptions import HttpError
33-
from ..graphql import (
33+
from ..graphql import ( # type: ignore[attr-defined]
3434
ExecutionResult,
3535
GraphQLError,
3636
parse_query,

ariadne/file_uploads.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,15 @@ def inverse_files_map(files_map: dict, files: FilesDict) -> dict:
9090
for field_name, paths in files_map.items():
9191
if not isinstance(paths, list):
9292
raise HttpBadRequestError(
93-
94-
"Invalid type for the 'map' multipart field entry "
95-
f"key '{field_name}' array ({SPEC_URL})."
96-
93+
"Invalid type for the 'map' multipart field entry "
94+
f"key '{field_name}' array ({SPEC_URL})."
9795
)
9896

9997
for i, path in enumerate(paths):
10098
if not isinstance(path, str):
10199
raise HttpBadRequestError(
102-
103-
"Invalid type for the 'map' multipart field entry key "
104-
f"'{field_name}' array index '{i}' value ({SPEC_URL})."
105-
100+
"Invalid type for the 'map' multipart field entry key "
101+
f"'{field_name}' array index '{i}' value ({SPEC_URL})."
106102
)
107103

108104
try:

ariadne/graphql.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ async def graphql(
107107
with two arguments: `context_value`, and `data` dict.
108108
109109
`query_validator`: a `QueryValidator` to use instead of default one. Is called
110-
with five arguments: `schema`, 'document_ast', 'rules', 'max_errors' and 'type_info'.
110+
with five arguments: `schema`, 'document_ast', 'rules', 'max_errors'
111+
and 'type_info'.
111112
112113
`query_document`: an already parsed GraphQL query. Setting this option will
113114
prevent `graphql` from parsing `query` string from `data` second time.
@@ -298,7 +299,8 @@ def graphql_sync(
298299
with two arguments: `context_value`, and `data` dict.
299300
300301
`query_validator`: a `QueryValidator` to use instead of default one. Is called
301-
with five arguments: `schema`, 'document_ast', 'rules', 'max_errors' and 'type_info'.
302+
with five arguments: `schema`, 'document_ast', 'rules', 'max_errors'
303+
and 'type_info'.
302304
303305
`query_document`: an already parsed GraphQL query. Setting this option will
304306
prevent `graphql_sync` from parsing `query` string from `data` second time.
@@ -466,7 +468,7 @@ async def subscribe(
466468
467469
Returns a tuple with two items:
468470
469-
`bool`: `True` when no errors occurred, `False` otherwise.
471+
`bool`: `True` when no errors occurred, `False` otherwise.f
470472
471473
`AsyncGenerator`: an async generator that server implementation should
472474
consume to retrieve messages to send to client.
@@ -490,7 +492,8 @@ async def subscribe(
490492
with two arguments: `context_value`, and `data` dict.
491493
492494
`query_validator`: a `QueryValidator` to use instead of default one. Is called
493-
with five arguments: `schema`, 'document_ast', 'rules', 'max_errors' and 'type_info'.
495+
with five arguments: `schema`, 'document_ast', 'rules', 'max_errors'
496+
and 'type_info'.
494497
495498
`query_document`: an already parsed GraphQL query. Setting this option will
496499
prevent `subscribe` from parsing `query` string from `data` second time.

ariadne/inputs.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -195,5 +195,7 @@ def validate_graphql_type(self, graphql_type: Optional[GraphQLNamedType]) -> Non
195195
raise ValueError(f"Type {self.name} is not defined in the schema")
196196
if not isinstance(graphql_type, GraphQLInputObjectType):
197197
raise ValueError(
198-
f"{self.name} is defined in the schema, but it is instance of {type(graphql_type).__name__} (expected {GraphQLInputObjectType.__name__})"
198+
f"{self.name} is defined in the schema, "
199+
f"but it is instance of {type(graphql_type).__name__} "
200+
f"(expected {GraphQLInputObjectType.__name__})"
199201
)

ariadne/interfaces.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ def set_type_resolver(self, type_resolver: Resolver) -> Resolver:
167167
```python
168168
interface_type = InterfaceType("MyInterface")
169169
170+
170171
@interface_type.type_resolver
171-
def type_resolver(obj: Any, *_) -> str:
172-
...
172+
def type_resolver(obj: Any, *_) -> str: ...
173173
```
174174
"""
175175
self._resolve_type = type_resolver

ariadne/objects.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ def __init__(self, name: str) -> None:
165165
self._resolvers = {}
166166

167167
def field(self, name: str) -> Callable[[Resolver], Resolver]:
168-
"""Return a decorator that sets decorated function as a resolver for named field.
168+
"""Return a decorator that sets decorated
169+
function as a resolver for named field.
169170
170171
Wrapper for `create_register_resolver` that on runtime validates `name` to be a
171172
string.
@@ -182,7 +183,8 @@ def field(self, name: str) -> Callable[[Resolver], Resolver]:
182183
return self.create_register_resolver(name)
183184

184185
def create_register_resolver(self, name: str) -> Callable[[Resolver], Resolver]:
185-
"""Return a decorator that sets decorated function as a resolver for named field.
186+
"""Return a decorator that sets decorated function
187+
as a resolver for named field.
186188
187189
# Required arguments
188190
@@ -240,16 +242,16 @@ def validate_graphql_type(self, graphql_type: Optional[GraphQLNamedType]) -> Non
240242
raise ValueError(f"Type {self.name} is not defined in the schema")
241243
if not isinstance(graphql_type, GraphQLObjectType):
242244
raise ValueError(
243-
f"{self.name} is defined in the schema, but it is instance of {type(graphql_type).__name__} (expected {GraphQLObjectType.__name__})"
245+
f"{self.name} is defined in the schema, "
246+
f"but it is instance of {type(graphql_type).__name__} "
247+
f"(expected {GraphQLObjectType.__name__})"
244248
)
245249

246250
def bind_resolvers_to_graphql_type(self, graphql_type, replace_existing=True):
247251
"""Binds this `ObjectType` instance to the instance of GraphQL schema."""
248252
for field, resolver in self._resolvers.items():
249253
if field not in graphql_type.fields:
250-
raise ValueError(
251-
f"Field {field} is not defined on type {self.name}"
252-
)
254+
raise ValueError(f"Field {field} is not defined on type {self.name}")
253255
if graphql_type.fields[field].resolve is None or replace_existing:
254256
graphql_type.fields[field].resolve = resolver
255257

ariadne/scalars.py

+12-19
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ def parse_date_str(value: str) -> date:
4949
# Parse "YYYY-MM-DD" string into date
5050
return datetime.strptime(value, "%Y-%m-%d").date()
5151
except (ValueError, TypeError):
52-
raise ValueError(
53-
f'"{value}" is not a date string in YYYY-MM-DD format.'
54-
)
52+
raise ValueError(f'"{value}" is not a date string in YYYY-MM-DD format.')
5553
```
5654
5755
# Literal parsing
@@ -63,19 +61,15 @@ def parse_date_str(value: str) -> date:
6361
query's variables and returns Python value:
6462
6563
```python
66-
def parse_date_literal(
67-
value: str, variable_values: dict[str, Any] = None
68-
) -> date:
64+
def parse_date_literal(value: str, variable_values: dict[str, Any] = None) -> date:
6965
if not isinstance(ast, StringValueNode):
7066
raise ValueError()
7167
7268
try:
7369
# Parse "YYYY-MM-DD" string into date
7470
return datetime.strptime(ast.value, "%Y-%m-%d").date()
7571
except (ValueError, TypeError):
76-
raise ValueError(
77-
f'"{value}" is not a date string in YYYY-MM-DD format.'
78-
)
72+
raise ValueError(f'"{value}" is not a date string in YYYY-MM-DD format.')
7973
```
8074
8175
When scalar has custom value parser set, but not the literal parser, the
@@ -225,6 +219,7 @@ def set_serializer(self, f: GraphQLScalarSerializer) -> GraphQLScalarSerializer:
225219
```python
226220
date_scalar = ScalarType("Date")
227221
222+
228223
@date_scalar.serializer
229224
def serialize_date(value: date) -> str:
230225
# Serialize dates as "YYYY-MM-DD" string
@@ -242,15 +237,14 @@ def set_value_parser(self, f: GraphQLScalarValueParser) -> GraphQLScalarValuePar
242237
```python
243238
date_scalar = ScalarType("Date")
244239
240+
245241
@date_scalar.value_parser
246242
def parse_date_str(value: str) -> date:
247243
try:
248244
# Parse "YYYY-MM-DD" string into date
249245
return datetime.strptime(value, "%Y-%m-%d").date()
250246
except (ValueError, TypeError):
251-
raise ValueError(
252-
f'"{value}" is not a date string in YYYY-MM-DD format.'
253-
)
247+
raise ValueError(f'"{value}" is not a date string in YYYY-MM-DD format.')
254248
```
255249
"""
256250
self._parse_value = f
@@ -266,20 +260,17 @@ def set_literal_parser(
266260
```python
267261
date_scalar = ScalarType("Date")
268262
263+
269264
@date_scalar.literal_parser
270-
def parse_date_literal(
271-
value: str, variable_values: Optional[dict[str, Any]] = None
272-
) -> date:
265+
def parse_date_literal(value: str, variable_values: Optional[dict[str, Any]] = None) -> date:
273266
if not isinstance(ast, StringValueNode):
274267
raise ValueError()
275268
276269
try:
277270
# Parse "YYYY-MM-DD" string into date
278271
return datetime.strptime(ast.value, "%Y-%m-%d").date()
279272
except (ValueError, TypeError):
280-
raise ValueError(
281-
f'"{value}" is not a date string in YYYY-MM-DD format.'
282-
)
273+
raise ValueError(f'"{value}" is not a date string in YYYY-MM-DD format.')
283274
```
284275
"""
285276
self._parse_literal = f
@@ -316,5 +307,7 @@ def validate_graphql_type(self, graphql_type: Optional[GraphQLNamedType]) -> Non
316307
raise ValueError(f"Scalar {self.name} is not defined in the schema")
317308
if not isinstance(graphql_type, GraphQLScalarType):
318309
raise ValueError(
319-
f"{self.name} is defined in the schema, but it is instance of {type(graphql_type).__name__} (expected {GraphQLScalarType.__name__})"
310+
f"{self.name} is defined in the schema, "
311+
f"but it is instance of {type(graphql_type).__name__} "
312+
f"(expected {GraphQLScalarType.__name__})"
320313
)

ariadne/schema_visitor.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def visit_input_field_definition(
155155
pass
156156

157157

158-
def visit_schema(
158+
def visit_schema( # noqa: C901
159159
schema: GraphQLSchema,
160160
visitor_selector: Callable[
161161
[VisitableSchemaType, str], list["SchemaDirectiveVisitor"]
@@ -347,6 +347,7 @@ class SchemaDirectiveVisitor(SchemaVisitor):
347347
GraphQLUnionType,
348348
)
349349
350+
350351
class MyDirective(SchemaDirectiveVisitor):
351352
def visit_schema(self, schema: GraphQLSchema) -> None:
352353
pass
@@ -386,9 +387,7 @@ def visit_enum_value(
386387
) -> GraphQLEnumValue:
387388
pass
388389
389-
def visit_input_object(
390-
self, object_: GraphQLInputObjectType
391-
) -> GraphQLInputObjectType:
390+
def visit_input_object(self, object_: GraphQLInputObjectType) -> GraphQLInputObjectType:
392391
pass
393392
394393
def visit_input_field_definition(
@@ -612,8 +611,8 @@ def _visitor_selector(
612611
NamedTypeMap = dict[str, GraphQLNamedType]
613612

614613

615-
def heal_schema(schema: GraphQLSchema) -> GraphQLSchema:
616-
def heal(type_: VisitableSchemaType):
614+
def heal_schema(schema: GraphQLSchema) -> GraphQLSchema: # noqa: C901
615+
def heal(type_: VisitableSchemaType): # noqa: C901
617616
if isinstance(type_, GraphQLSchema):
618617
original_type_map: NamedTypeMap = type_.type_map
619618
actual_named_type_map: NamedTypeMap = {}
@@ -716,7 +715,7 @@ def _heal_field(field, _):
716715
each(type_.fields, _heal_field)
717716

718717
def heal_type(
719-
type_: Union[GraphQLList, GraphQLNamedType, GraphQLNonNull]
718+
type_: Union[GraphQLList, GraphQLNamedType, GraphQLNonNull],
720719
) -> Union[GraphQLList, GraphQLNamedType, GraphQLNonNull]:
721720
# Unwrap the two known wrapper types
722721
if isinstance(type_, GraphQLList):

ariadne/subscriptions.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ class SubscriptionType(ObjectType):
2121
Its signature is same as resolver:
2222
2323
```python
24-
async def source_fn(
25-
root_value: Any, info: GraphQLResolveInfo, **field_args
26-
) -> Any:
24+
async def source_fn(root_value: Any, info: GraphQLResolveInfo, **field_args) -> Any:
2725
yield ...
2826
```
2927
@@ -35,9 +33,7 @@ async def source_fn(
3533
source function as first argument.
3634
3735
```python
38-
def resolver_fn(
39-
message: Any, info: GraphQLResolveInfo, **field_args
40-
) -> Any:
36+
def resolver_fn(message: Any, info: GraphQLResolveInfo, **field_args) -> Any:
4137
# Subscription resolver can be sync and async.
4238
return ...
4339
```
@@ -117,8 +113,8 @@ def __init__(self) -> None:
117113
def source(self, name: str) -> Callable[[Subscriber], Subscriber]:
118114
"""Return a decorator that sets decorated function as a source for named field.
119115
120-
Wrapper for `create_register_subscriber` that on runtime validates `name` to be a
121-
string.
116+
Wrapper for `create_register_subscriber` that on runtime
117+
validates `name` to be a string.
122118
123119
# Required arguments
124120
@@ -179,8 +175,6 @@ def bind_subscribers_to_graphql_type(self, graphql_type):
179175
"""
180176
for field, subscriber in self._subscribers.items():
181177
if field not in graphql_type.fields:
182-
raise ValueError(
183-
f"Field {field} is not defined on type {self.name}"
184-
)
178+
raise ValueError(f"Field {field} is not defined on type {self.name}")
185179

186180
graphql_type.fields[field].subscribe = subscriber

0 commit comments

Comments
 (0)