Skip to content

Commit 103278b

Browse files
committed
chore: DROP 3.8, leverage hatch to run tests and static analisys
- provide explicit configs for mypy, ruff, coverage - Python 3.8 support is dropped - Python 3.13 support introduced
1 parent c20a689 commit 103278b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+429
-389
lines changed

ariadne/asgi/graphql.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from collections.abc import Awaitable
12
from logging import Logger, LoggerAdapter
2-
from typing import Any, Awaitable, Optional, Type, Union
3+
from typing import Any, Optional, Union
34

45
from graphql import ExecutionContext, GraphQLSchema
56
from starlette.requests import Request
@@ -45,7 +46,7 @@ def __init__(
4546
explorer: Optional[Explorer] = None,
4647
logger: Union[None, str, Logger, LoggerAdapter] = None,
4748
error_formatter: ErrorFormatter = format_error,
48-
execution_context_class: Optional[Type[ExecutionContext]] = None,
49+
execution_context_class: Optional[type[ExecutionContext]] = None,
4950
http_handler: Optional[GraphQLHTTPHandler] = None,
5051
websocket_handler: Optional[GraphQLWebsocketHandler] = None,
5152
) -> None:
@@ -182,7 +183,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send):
182183
elif scope["type"] == "websocket":
183184
await self.websocket_handler.handle(scope=scope, receive=receive, send=send)
184185
else:
185-
raise ValueError("Unknown scope type: %r" % (scope["type"],))
186+
raise ValueError("Unknown scope type: {!r}".format(scope["type"]))
186187

187188
async def handle_request(self, request: Request) -> Response:
188189
"""Shortcut for `graphql_app.http_handler.handle_request(...)`."""

ariadne/asgi/handlers/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from .base import GraphQLHandler, GraphQLHttpHandlerBase, GraphQLWebsocketHandler
2-
from .http import GraphQLHTTPHandler
32
from .graphql_transport_ws import GraphQLTransportWSHandler
43
from .graphql_ws import GraphQLWSHandler
5-
4+
from .http import GraphQLHTTPHandler
65

76
__all__ = [
87
"GraphQLHandler",

ariadne/asgi/handlers/base.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from abc import ABC, abstractmethod
22
from inspect import isawaitable
33
from logging import Logger, LoggerAdapter
4-
from typing import Any, Optional, Type, Union
4+
from typing import Any, Optional, Union
55

66
from graphql import DocumentNode, ExecutionContext, GraphQLSchema, MiddlewareManager
77
from starlette.types import Receive, Scope, Send
@@ -41,8 +41,8 @@ def __init__(self) -> None:
4141
self.query_validator: Optional[QueryValidator] = None
4242
self.validation_rules: Optional[ValidationRules] = None
4343
self.execute_get_queries: bool = False
44-
self.execution_context_class: Optional[Type[ExecutionContext]] = None
45-
self.middleware_manager_class: Optional[Type[MiddlewareManager]] = None
44+
self.execution_context_class: Optional[type[ExecutionContext]] = None
45+
self.middleware_manager_class: Optional[type[MiddlewareManager]] = None
4646

4747
@abstractmethod
4848
async def handle(self, scope: Scope, receive: Receive, send: Send):
@@ -86,7 +86,7 @@ def configure(
8686
explorer: Optional[Explorer] = None,
8787
logger: Union[None, str, Logger, LoggerAdapter] = None,
8888
error_formatter: ErrorFormatter = format_error,
89-
execution_context_class: Optional[Type[ExecutionContext]] = None,
89+
execution_context_class: Optional[type[ExecutionContext]] = None,
9090
):
9191
"""Configures the handler with options from the ASGI application.
9292

ariadne/asgi/handlers/graphql_transport_ws.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import asyncio
2+
from collections.abc import AsyncGenerator
23
from contextlib import suppress
34
from datetime import timedelta
45
from inspect import isawaitable
5-
from typing import Any, AsyncGenerator, Dict, List, Optional, cast
6+
from typing import Any, Optional, cast
67

78
from graphql import GraphQLError
89
from graphql.language import OperationType
910
from starlette.types import Receive, Scope, Send
1011
from starlette.websockets import WebSocket, WebSocketDisconnect, WebSocketState
1112

12-
from ...graphql import subscribe, parse_query, validate_data
13+
from ...graphql import parse_query, subscribe, validate_data
1314
from ...logger import log_error
1415
from ...types import (
1516
ExecutionResult,
@@ -24,8 +25,8 @@ def __init__(self) -> None:
2425
self.connection_acknowledged: bool = False
2526
self.connection_init_timeout_task: Optional[asyncio.Task] = None
2627
self.connection_init_received: bool = False
27-
self.operations: Dict[str, Operation] = {}
28-
self.operation_tasks: Dict[str, asyncio.Task] = {}
28+
self.operations: dict[str, Operation] = {}
29+
self.operation_tasks: dict[str, asyncio.Task] = {}
2930
self.websocket: WebSocket
3031

3132

@@ -374,7 +375,7 @@ async def get_results():
374375

375376
if not success:
376377
if not isinstance(results_producer, list):
377-
error_payload = cast(List[dict], [results_producer])
378+
error_payload = cast(list[dict], [results_producer])
378379
else:
379380
error_payload = results_producer
380381

@@ -524,7 +525,8 @@ async def observe_async_results(
524525
}
525526
)
526527
except asyncio.CancelledError: # pylint: disable=W0706
527-
# if asyncio Task is cancelled then CancelledError is thrown in the coroutine
528+
# if asyncio Task is cancelled then CancelledError
529+
# is thrown in the coroutine
528530
raise
529531
except Exception as error:
530532
if not isinstance(error, GraphQLError):

ariadne/asgi/handlers/graphql_ws.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
2+
from collections.abc import AsyncGenerator
23
from inspect import isawaitable
3-
from typing import Any, AsyncGenerator, Dict, List, Optional, cast
4+
from typing import Any, Optional, cast
45

56
from graphql import DocumentNode, GraphQLError
67
from graphql.language import OperationType
@@ -104,7 +105,7 @@ async def handle_websocket(self, websocket: WebSocket):
104105
105106
`websocket`: the `WebSocket` instance from Starlette or FastAPI.
106107
"""
107-
operations: Dict[str, Operation] = {}
108+
operations: dict[str, Operation] = {}
108109
await websocket.accept("graphql-ws")
109110
try:
110111
while WebSocketState.DISCONNECTED not in (
@@ -134,7 +135,7 @@ async def handle_websocket_message(
134135
self,
135136
websocket: WebSocket,
136137
message: dict,
137-
operations: Dict[str, Operation],
138+
operations: dict[str, Operation],
138139
):
139140
"""Handles new message from websocket connection.
140141
@@ -167,7 +168,7 @@ async def process_single_message(
167168
websocket: WebSocket,
168169
data: Any,
169170
operation_id: str,
170-
operations: Dict[str, Operation],
171+
operations: dict[str, Operation],
171172
) -> None:
172173
"""Processes websocket message containing new GraphQL operation.
173174
@@ -290,7 +291,7 @@ async def start_websocket_operation(
290291
context_value: Any,
291292
query_document: DocumentNode,
292293
operation_id: str,
293-
operations: Dict[str, Operation],
294+
operations: dict[str, Operation],
294295
):
295296
if self.schema is None:
296297
raise TypeError("schema is not set, call configure method to initialize it")
@@ -310,7 +311,7 @@ async def start_websocket_operation(
310311
)
311312

312313
if not success:
313-
results = cast(List[dict], results)
314+
results = cast(list[dict], results)
314315
await websocket.send_json(
315316
{
316317
"type": GraphQLWSHandler.GQL_ERROR,

ariadne/asgi/handlers/http.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
from http import HTTPStatus
33
from inspect import isawaitable
4-
from typing import Any, Optional, Type, Union, cast
4+
from typing import Any, Optional, Union, cast
55

66
from graphql import DocumentNode, MiddlewareManager
77
from starlette.datastructures import UploadFile
@@ -38,7 +38,7 @@ def __init__(
3838
self,
3939
extensions: Optional[Extensions] = None,
4040
middleware: Optional[Middlewares] = None,
41-
middleware_manager_class: Optional[Type[MiddlewareManager]] = None,
41+
middleware_manager_class: Optional[type[MiddlewareManager]] = None,
4242
) -> None:
4343
"""Initializes the HTTP handler.
4444

ariadne/contrib/federation/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
from .interfaces import FederatedInterfaceType
88
from .objects import FederatedObjectType
99
from .schema import make_federated_schema
10+
11+
__all__ = ["FederatedInterfaceType", "FederatedObjectType", "make_federated_schema"]

ariadne/contrib/federation/schema.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import re
21
import os
3-
from typing import Dict, List, Optional, Type, Union, cast
2+
import re
3+
from typing import Optional, Union, cast
44

55
from graphql import extend_schema, parse
66
from graphql.language import DocumentNode
@@ -13,12 +13,12 @@
1313

1414
from ...executable_schema import (
1515
SchemaBindables,
16-
make_executable_schema,
1716
join_type_defs,
17+
make_executable_schema,
1818
)
19+
from ...load_schema import load_schema_from_path
1920
from ...schema_names import SchemaNameConverter
2021
from ...schema_visitor import SchemaDirectiveVisitor
21-
from ...load_schema import load_schema_from_path
2222
from .utils import get_entity_types, purge_schema_directives, resolve_entities
2323

2424
base_federation_service_type_defs = """
@@ -54,9 +54,9 @@ def has_query_type(type_defs: str) -> bool:
5454

5555

5656
def make_federated_schema(
57-
type_defs: Union[str, List[str]],
57+
type_defs: Union[str, list[str]],
5858
*bindables: SchemaBindables,
59-
directives: Optional[Dict[str, Type[SchemaDirectiveVisitor]]] = None,
59+
directives: Optional[dict[str, type[SchemaDirectiveVisitor]]] = None,
6060
convert_names_case: Union[bool, SchemaNameConverter] = False,
6161
) -> GraphQLSchema:
6262
if isinstance(type_defs, list):

ariadne/contrib/federation/utils.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# pylint: disable=cell-var-from-loop
22

33
from inspect import isawaitable
4-
from typing import Any, List, Tuple, cast
4+
from typing import Any, cast
55

66
from graphql import (
77
DirectiveDefinitionNode,
@@ -11,14 +11,13 @@
1111
)
1212
from graphql.language import DirectiveNode
1313
from graphql.type import (
14-
GraphQLNamedType,
1514
GraphQLInputObjectType,
15+
GraphQLNamedType,
1616
GraphQLObjectType,
1717
GraphQLResolveInfo,
1818
GraphQLSchema,
1919
)
2020

21-
2221
_allowed_directives = [
2322
"skip", # Default directive as per specs.
2423
"include", # Default directive as per specs.
@@ -41,7 +40,7 @@
4140
]
4241

4342

44-
def _purge_directive_nodes(nodes: Tuple[Node, ...]) -> Tuple[Node, ...]:
43+
def _purge_directive_nodes(nodes: tuple[Node, ...]) -> tuple[Node, ...]:
4544
return tuple(
4645
node
4746
for node in nodes
@@ -58,11 +57,11 @@ def _purge_type_directives(definition: Node):
5857
if isinstance(value, tuple):
5958
# Remove directive nodes from the tuple
6059
# e.g. doc -> definitions [DirectiveDefinitionNode]
61-
next_value = _purge_directive_nodes(cast(Tuple[Node, ...], value))
60+
next_value = _purge_directive_nodes(cast(tuple[Node, ...], value))
6261
for item in next_value:
6362
if isinstance(item, Node):
64-
# Look for directive nodes on sub-nodes
65-
# e.g. doc -> definitions [ObjectTypeDefinitionNode] -> fields -> directives
63+
# Look for directive nodes on sub-nodes, e.g.: doc ->
64+
# definitions [ObjectTypeDefinitionNode] -> fields -> directives
6665
_purge_type_directives(item)
6766
setattr(definition, key, next_value)
6867
elif isinstance(value, Node):
@@ -111,7 +110,7 @@ async def add_typename_to_async_return(obj: Any, typename: str) -> Any:
111110
return add_typename_to_possible_return(await obj, typename)
112111

113112

114-
def get_entity_types(schema: GraphQLSchema) -> List[GraphQLNamedType]:
113+
def get_entity_types(schema: GraphQLSchema) -> list[GraphQLNamedType]:
115114
"""Get all types that include the @key directive."""
116115
schema_types = schema.type_map.values()
117116

@@ -135,9 +134,9 @@ def includes_directive(
135134

136135
def gather_directives(
137136
type_object: GraphQLNamedType,
138-
) -> List[DirectiveNode]:
137+
) -> list[DirectiveNode]:
139138
"""Get all directive attached to a type."""
140-
directives: List[DirectiveNode] = []
139+
directives: list[DirectiveNode] = []
141140

142141
if hasattr(type_object, "extension_ast_nodes") and type_object.extension_ast_nodes:
143142
for ast_node in type_object.extension_ast_nodes:

0 commit comments

Comments
 (0)