Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8f4d245

Browse filesBrowse files
committed
More modernization of typing annotations in tests
1 parent 10a2d8a commit 8f4d245
Copy full SHA for 8f4d245
Expand file treeCollapse file tree

37 files changed

+215
-144
lines changed

‎tests/error/test_graphql_error.py

Copy file name to clipboardExpand all lines: tests/error/test_graphql_error.py
+8-6Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from typing import List, Union, cast
1+
from __future__ import annotations
2+
3+
from typing import cast
24

35
from graphql.error import GraphQLError
46
from graphql.language import (
@@ -204,7 +206,7 @@ def serializes_to_include_message_and_locations():
204206
}
205207

206208
def serializes_to_include_path():
207-
path: List[Union[int, str]] = ["path", 3, "to", "field"]
209+
path: list[int | str] = ["path", 3, "to", "field"]
208210
e = GraphQLError("msg", path=path)
209211
assert e.path is path
210212
assert repr(e) == "GraphQLError('msg', path=['path', 3, 'to', 'field'])"
@@ -218,7 +220,7 @@ def serializes_to_include_all_standard_fields():
218220
assert str(e_short) == "msg"
219221
assert repr(e_short) == "GraphQLError('msg')"
220222

221-
path: List[Union[str, int]] = ["path", 2, "field"]
223+
path: list[str | int] = ["path", 2, "field"]
222224
extensions = {"foo": "bar "}
223225
e_full = GraphQLError("msg", field_node, None, None, path, None, extensions)
224226
assert str(e_full) == (
@@ -240,7 +242,7 @@ def repr_includes_extensions():
240242
assert repr(e) == "GraphQLError('msg', extensions={'foo': 'bar'})"
241243

242244
def always_stores_path_as_list():
243-
path: List[Union[int, str]] = ["path", 3, "to", "field"]
245+
path: list[int | str] = ["path", 3, "to", "field"]
244246
e = GraphQLError("msg,", path=tuple(path))
245247
assert isinstance(e.path, list)
246248
assert e.path == path
@@ -346,7 +348,7 @@ def prints_an_error_with_nodes_from_different_sources():
346348

347349
def describe_formatted():
348350
def formats_graphql_error():
349-
path: List[Union[int, str]] = ["one", 2]
351+
path: list[int | str] = ["one", 2]
350352
extensions = {"ext": None}
351353
error = GraphQLError(
352354
"test message",
@@ -379,7 +381,7 @@ def uses_default_message():
379381
}
380382

381383
def includes_path():
382-
path: List[Union[int, str]] = ["path", 3, "to", "field"]
384+
path: list[int | str] = ["path", 3, "to", "field"]
383385
error = GraphQLError("msg", path=path)
384386
assert error.formatted == {"message": "msg", "path": path}
385387

‎tests/execution/test_abstract.py

Copy file name to clipboardExpand all lines: tests/execution/test_abstract.py
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from typing import Any, NamedTuple, Optional
1+
from __future__ import annotations
2+
3+
from typing import Any, NamedTuple
24

35
import pytest
46
from graphql.execution import ExecutionResult, execute, execute_sync
@@ -448,19 +450,19 @@ class RootValueAsObject:
448450

449451
class Pet:
450452
__typename = "Pet"
451-
name: Optional[str] = None
453+
name: str | None = None
452454

453455
class DogPet(Pet):
454456
__typename = "Dog"
455-
woofs: Optional[bool] = None
457+
woofs: bool | None = None
456458

457459
class Odie(DogPet):
458460
name = "Odie"
459461
woofs = True
460462

461463
class CatPet(Pet):
462464
__typename = "Cat"
463-
meows: Optional[bool] = None
465+
meows: bool | None = None
464466

465467
class Tabby(CatPet):
466468
pass

‎tests/execution/test_defer.py

Copy file name to clipboardExpand all lines: tests/execution/test_defer.py
+8-6Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from __future__ import annotations
2+
13
from asyncio import sleep
2-
from typing import Any, AsyncGenerator, Dict, List, NamedTuple
4+
from typing import Any, AsyncGenerator, NamedTuple
35

46
import pytest
57
from graphql.error import GraphQLError
@@ -111,7 +113,7 @@ async def complete(document: DocumentNode, root_value: Any = None) -> Any:
111113
result = await result
112114

113115
if isinstance(result, ExperimentalIncrementalExecutionResults):
114-
results: List[Any] = [result.initial_result.formatted]
116+
results: list[Any] = [result.initial_result.formatted]
115117
async for patch in result.subsequent_results:
116118
results.append(patch.formatted)
117119
return results
@@ -120,7 +122,7 @@ async def complete(document: DocumentNode, root_value: Any = None) -> Any:
120122
return result.formatted
121123

122124

123-
def modified_args(args: Dict[str, Any], **modifications: Any) -> Dict[str, Any]:
125+
def modified_args(args: dict[str, Any], **modifications: Any) -> dict[str, Any]:
124126
return {**args, **modifications}
125127

126128

@@ -152,7 +154,7 @@ def can_format_and_print_incremental_defer_result():
152154

153155
# noinspection PyTypeChecker
154156
def can_compare_incremental_defer_result():
155-
args: Dict[str, Any] = {
157+
args: dict[str, Any] = {
156158
"data": {"hello": "world"},
157159
"errors": [GraphQLError("msg")],
158160
"path": ["foo", 1],
@@ -219,7 +221,7 @@ def can_format_and_print_initial_incremental_execution_result():
219221

220222
def can_compare_initial_incremental_execution_result():
221223
incremental = [IncrementalDeferResult(label="foo")]
222-
args: Dict[str, Any] = {
224+
args: dict[str, Any] = {
223225
"data": {"hello": "world"},
224226
"errors": [GraphQLError("msg")],
225227
"incremental": incremental,
@@ -298,7 +300,7 @@ def can_format_and_print_subsequent_incremental_execution_result():
298300

299301
def can_compare_subsequent_incremental_execution_result():
300302
incremental = [IncrementalDeferResult(label="foo")]
301-
args: Dict[str, Any] = {
303+
args: dict[str, Any] = {
302304
"incremental": incremental,
303305
"has_next": True,
304306
"extensions": {"baz": 2},

‎tests/execution/test_executor.py

Copy file name to clipboardExpand all lines: tests/execution/test_executor.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from __future__ import annotations
2+
13
import asyncio
2-
from typing import Any, Awaitable, Optional, cast
4+
from typing import Any, Awaitable, cast
35

46
import pytest
57
from graphql.error import GraphQLError
@@ -263,7 +265,7 @@ def resolve(_obj, info):
263265
)
264266

265267
def it_populates_path_correctly_with_complex_types():
266-
path: Optional[ResponsePath] = None
268+
path: ResponsePath | None = None
267269

268270
def resolve(_val, info):
269271
nonlocal path

‎tests/execution/test_mutations.py

Copy file name to clipboardExpand all lines: tests/execution/test_mutations.py
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from __future__ import annotations
2+
13
from asyncio import sleep
2-
from typing import Any, Awaitable, List
4+
from typing import Any, Awaitable
35

46
import pytest
57
from graphql.execution import (
@@ -232,7 +234,7 @@ async def mutation_fields_with_defer_do_not_block_next_mutation():
232234
schema, document, root_value
233235
)
234236

235-
patches: List[Any] = []
237+
patches: list[Any] = []
236238
assert isinstance(mutation_result, ExperimentalIncrementalExecutionResults)
237239
patches.append(mutation_result.initial_result.formatted)
238240
async for patch in mutation_result.subsequent_results:
@@ -303,7 +305,7 @@ async def mutation_with_defer_is_not_executed_serially():
303305
schema, document, root_value
304306
)
305307

306-
patches: List[Any] = []
308+
patches: list[Any] = []
307309
assert isinstance(mutation_result, ExperimentalIncrementalExecutionResults)
308310
patches.append(mutation_result.initial_result.formatted)
309311
async for patch in mutation_result.subsequent_results:

‎tests/execution/test_stream.py

Copy file name to clipboardExpand all lines: tests/execution/test_stream.py
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from __future__ import annotations
2+
13
from asyncio import Event, Lock, gather, sleep
2-
from typing import Any, Awaitable, Dict, List, NamedTuple
4+
from typing import Any, Awaitable, NamedTuple
35

46
import pytest
57
from graphql.error import GraphQLError
@@ -91,7 +93,7 @@ async def complete(document: DocumentNode, root_value: Any = None) -> Any:
9193
result = await result
9294

9395
if isinstance(result, ExperimentalIncrementalExecutionResults):
94-
results: List[Any] = [result.initial_result.formatted]
96+
results: list[Any] = [result.initial_result.formatted]
9597
async for patch in result.subsequent_results:
9698
results.append(patch.formatted)
9799
return results
@@ -140,7 +142,7 @@ async def locked_next():
140142
return [IteratorResult(result).formatted for result in results]
141143

142144

143-
def modified_args(args: Dict[str, Any], **modifications: Any) -> Dict[str, Any]:
145+
def modified_args(args: dict[str, Any], **modifications: Any) -> dict[str, Any]:
144146
return {**args, **modifications}
145147

146148

@@ -187,7 +189,7 @@ def can_print_stream_record():
187189

188190
# noinspection PyTypeChecker
189191
def can_compare_incremental_stream_result():
190-
args: Dict[str, Any] = {
192+
args: dict[str, Any] = {
191193
"items": ["hello", "world"],
192194
"errors": [GraphQLError("msg")],
193195
"path": ["foo", 1],

‎tests/execution/test_variables.py

Copy file name to clipboardExpand all lines: tests/execution/test_variables.py
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from __future__ import annotations
2+
13
from math import nan
2-
from typing import Any, Dict, Optional
4+
from typing import Any
35

46
from graphql.error import GraphQLError
57
from graphql.execution import ExecutionResult, execute_sync
@@ -153,7 +155,7 @@ def field_with_input_arg(input_arg: GraphQLArgument):
153155

154156

155157
def execute_query(
156-
query: str, variable_values: Optional[Dict[str, Any]] = None
158+
query: str, variable_values: dict[str, Any] | None = None
157159
) -> ExecutionResult:
158160
document = parse(query)
159161
return execute_sync(schema, document, variable_values=variable_values)
@@ -1039,7 +1041,7 @@ def describe_get_variable_values_limit_maximum_number_of_coercion_errors():
10391041

10401042
input_value = {"input": [0, 1, 2]}
10411043

1042-
def _invalid_value_error(value: int, index: int) -> Dict[str, Any]:
1044+
def _invalid_value_error(value: int, index: int) -> dict[str, Any]:
10431045
return {
10441046
"message": "Variable '$input' got invalid value"
10451047
f" {value} at 'input[{index}]';"

‎tests/language/test_ast.py

Copy file name to clipboardExpand all lines: tests/language/test_ast.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from __future__ import annotations
2+
13
import weakref
24
from copy import copy, deepcopy
3-
from typing import Optional
45

56
from graphql.language import Location, NameNode, Node, Source, Token, TokenKind
67
from graphql.pyutils import inspect
@@ -17,7 +18,7 @@ class SampleNamedNode(Node):
1718
__slots__ = "foo", "name"
1819

1920
foo: str
20-
name: Optional[str]
21+
name: str | None
2122

2223

2324
def describe_token_class():

‎tests/language/test_block_string.py

Copy file name to clipboardExpand all lines: tests/language/test_block_string.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from typing import Collection, Optional, cast
1+
from __future__ import annotations
2+
3+
from typing import Collection, cast
24

35
from graphql.language.block_string import (
46
dedent_block_string_lines,
@@ -152,7 +154,7 @@ def __str__(self) -> str:
152154

153155
def describe_print_block_string():
154156
def _assert_block_string(
155-
s: str, readable: str, minimize: Optional[str] = None
157+
s: str, readable: str, minimize: str | None = None
156158
) -> None:
157159
assert print_block_string(s) == readable
158160
assert print_block_string(s, minimize=True) == minimize or readable

‎tests/language/test_lexer.py

Copy file name to clipboardExpand all lines: tests/language/test_lexer.py
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from typing import List, Optional, Tuple
1+
from __future__ import annotations
2+
3+
from typing import Optional, Tuple
24

35
import pytest
46
from graphql.error import GraphQLSyntaxError
@@ -576,8 +578,8 @@ def produces_double_linked_list_of_tokens_including_comments():
576578
assert end_token.kind != TokenKind.COMMENT
577579
assert start_token.prev is None
578580
assert end_token.next is None
579-
tokens: List[Token] = []
580-
tok: Optional[Token] = start_token
581+
tokens: list[Token] = []
582+
tok: Token | None = start_token
581583
while tok:
582584
assert not tokens or tok.prev == tokens[-1]
583585
tokens.append(tok)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.