Skip to content

Commit f7ce55c

Browse files
committed
Fix issues with newer mypy version
1 parent bfc4b94 commit f7ce55c

File tree

11 files changed

+80
-80
lines changed

11 files changed

+80
-80
lines changed

Diff for: src/graphql/execution/execute.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
Iterable,
1111
List,
1212
Optional,
13-
Union,
1413
Tuple,
1514
Type,
15+
Union,
1616
cast,
1717
)
1818

@@ -30,25 +30,27 @@
3030
OperationType,
3131
)
3232
from ..pyutils import (
33-
inspect,
34-
is_awaitable as default_is_awaitable,
35-
is_iterable,
3633
AwaitableOrValue,
3734
Path,
3835
Undefined,
36+
inspect,
37+
is_iterable,
38+
)
39+
from ..pyutils import (
40+
is_awaitable as default_is_awaitable,
3941
)
4042
from ..type import (
4143
GraphQLAbstractType,
4244
GraphQLField,
45+
GraphQLFieldResolver,
4346
GraphQLLeafType,
4447
GraphQLList,
4548
GraphQLNonNull,
4649
GraphQLObjectType,
4750
GraphQLOutputType,
51+
GraphQLResolveInfo,
4852
GraphQLSchema,
49-
GraphQLFieldResolver,
5053
GraphQLTypeResolver,
51-
GraphQLResolveInfo,
5254
SchemaMetaFieldDef,
5355
TypeMetaFieldDef,
5456
TypeNameMetaFieldDef,
@@ -213,13 +215,13 @@ def __init__(
213215
self.context_value = context_value
214216
self.operation = operation
215217
self.variable_values = variable_values
216-
self.field_resolver = field_resolver # type: ignore
217-
self.type_resolver = type_resolver # type: ignore
218-
self.subscribe_field_resolver = subscribe_field_resolver # type: ignore
218+
self.field_resolver = field_resolver
219+
self.type_resolver = type_resolver
220+
self.subscribe_field_resolver = subscribe_field_resolver
219221
self.errors = errors
220222
self.middleware_manager = middleware_manager
221223
if is_awaitable:
222-
self.is_awaitable = is_awaitable
224+
self.is_awaitable = is_awaitable # type: ignore
223225
self._subfields_cache: Dict[Tuple, Dict[str, List[FieldNode]]] = {}
224226

225227
@classmethod
@@ -793,7 +795,7 @@ def complete_abstract_value(
793795
that value, then complete the value for that type.
794796
"""
795797
resolve_type_fn = return_type.resolve_type or self.type_resolver
796-
runtime_type = resolve_type_fn(result, info, return_type) # type: ignore
798+
runtime_type = resolve_type_fn(result, info, return_type)
797799

798800
if self.is_awaitable(runtime_type):
799801
runtime_type = cast(Awaitable, runtime_type)
@@ -1096,10 +1098,10 @@ def execute_sync(
10961098

10971099
# Assert that the execution was synchronous.
10981100
if isawaitable(result):
1099-
ensure_future(cast(Awaitable[ExecutionResult], result)).cancel()
1101+
ensure_future(result).cancel()
11001102
raise RuntimeError("GraphQL execution failed to complete synchronously.")
11011103

1102-
return cast(ExecutionResult, result)
1104+
return result
11031105

11041106

11051107
def assert_valid_execution_arguments(

Diff for: src/graphql/graphql.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from asyncio import ensure_future
22
from inspect import isawaitable
3-
from typing import Any, Awaitable, Callable, Dict, Optional, Union, Type, cast
3+
from typing import Any, Callable, Dict, Optional, Type, Union
44

55
from .error import GraphQLError
6-
from .execution import execute, ExecutionResult, ExecutionContext, Middleware
7-
from .language import parse, Source
6+
from .execution import ExecutionContext, ExecutionResult, Middleware, execute
7+
from .language import Source, parse
88
from .pyutils import AwaitableOrValue
99
from .type import (
1010
GraphQLFieldResolver,
@@ -90,9 +90,9 @@ async def graphql(
9090
)
9191

9292
if isawaitable(result):
93-
return await cast(Awaitable[ExecutionResult], result)
93+
return await result
9494

95-
return cast(ExecutionResult, result)
95+
return result
9696

9797

9898
def assume_not_awaitable(_value: Any) -> bool:
@@ -143,10 +143,10 @@ def graphql_sync(
143143

144144
# Assert that the execution was synchronous.
145145
if isawaitable(result):
146-
ensure_future(cast(Awaitable[ExecutionResult], result)).cancel()
146+
ensure_future(result).cancel()
147147
raise RuntimeError("GraphQL execution failed to complete synchronously.")
148148

149-
return cast(ExecutionResult, result)
149+
return result
150150

151151

152152
def graphql_impl(

Diff for: src/graphql/pyutils/frozen_dict.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__all__ = ["FrozenDict"]
77

88
KT = TypeVar("KT")
9-
VT = TypeVar("VT", covariant=True)
9+
VT = TypeVar("VT")
1010

1111

1212
class FrozenDict(Dict[KT, VT]):
@@ -25,7 +25,7 @@ def __setitem__(self, key, value):
2525
def __iadd__(self, value):
2626
raise FrozenError
2727

28-
def __hash__(self):
28+
def __hash__(self) -> int: # type: ignore
2929
return hash(tuple(self.items()))
3030

3131
def __copy__(self) -> "FrozenDict":
@@ -48,5 +48,5 @@ def popitem(self):
4848
def setdefault(self, key, default=None):
4949
raise FrozenError
5050

51-
def update(self, other=None):
51+
def update(self, other=None): # type: ignore
5252
raise FrozenError

Diff for: src/graphql/pyutils/frozen_list.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__all__ = ["FrozenList"]
77

88

9-
T = TypeVar("T", covariant=True)
9+
T = TypeVar("T")
1010

1111

1212
class FrozenList(List[T]):
@@ -36,7 +36,7 @@ def __mul__(self, value):
3636
def __imul__(self, value):
3737
raise FrozenError
3838

39-
def __hash__(self):
39+
def __hash__(self) -> int: # type: ignore
4040
return hash(tuple(self))
4141

4242
def __copy__(self) -> "FrozenList":

Diff for: src/graphql/type/definition.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,10 @@ def fields(self) -> GraphQLFieldMap:
833833
)
834834
return {
835835
assert_name(name): (
836-
value if isinstance(value, GraphQLField) else GraphQLField(value)
837-
) # type: ignore
836+
value
837+
if isinstance(value, GraphQLField)
838+
else GraphQLField(value) # type: ignore
839+
)
838840
for name, value in fields.items()
839841
}
840842

@@ -967,8 +969,10 @@ def fields(self) -> GraphQLFieldMap:
967969
)
968970
return {
969971
assert_name(name): (
970-
value if isinstance(value, GraphQLField) else GraphQLField(value)
971-
) # type: ignore
972+
value
973+
if isinstance(value, GraphQLField)
974+
else GraphQLField(value) # type: ignore
975+
)
972976
for name, value in fields.items()
973977
}
974978

@@ -1175,12 +1179,12 @@ def __init__(
11751179
):
11761180
try:
11771181
# noinspection PyTypeChecker
1178-
values = dict(values) # type: ignore
1179-
except (TypeError, ValueError):
1182+
values = dict(values)
1183+
except (TypeError, ValueError) as error:
11801184
raise TypeError(
11811185
f"{name} values must be an Enum or a mapping"
11821186
" with value names as keys."
1183-
)
1187+
) from error
11841188
values = cast(Dict[str, Any], values)
11851189
else:
11861190
values = cast(Dict[str, Enum], values)
@@ -1488,8 +1492,8 @@ def fields(self) -> GraphQLInputFieldMap:
14881492
assert_name(name): (
14891493
value
14901494
if isinstance(value, GraphQLInputField)
1491-
else GraphQLInputField(value)
1492-
) # type: ignore
1495+
else GraphQLInputField(value) # type: ignore
1496+
)
14931497
for name, value in fields.items()
14941498
}
14951499

Diff for: src/graphql/validation/validate.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from ..error import GraphQLError
44
from ..language import DocumentNode, ParallelVisitor, visit
5-
from ..type import GraphQLSchema, assert_valid_schema
65
from ..pyutils import inspect, is_collection
6+
from ..type import GraphQLSchema, assert_valid_schema
77
from ..utilities import TypeInfo, TypeInfoVisitor
88
from .rules import ASTValidationRule
99
from .specified_rules import specified_rules, specified_sdl_rules
@@ -65,7 +65,7 @@ def validate(
6565
errors: List[GraphQLError] = []
6666

6767
def on_error(error: GraphQLError) -> None:
68-
if len(errors) >= max_errors: # type: ignore
68+
if len(errors) >= max_errors:
6969
errors.append(
7070
GraphQLError(
7171
"Too many validation errors, error limit reached."

Diff for: tests/execution/test_map_async_iterator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
is_pypy = platform.python_implementation() == "PyPy"
99

1010
try: # pragma: no cover
11-
anext
11+
anext # type: ignore
1212
except NameError: # pragma: no cover (Python < 3.10)
1313
# noinspection PyShadowingBuiltins
1414
async def anext(iterator):

Diff for: tests/execution/test_subscribe.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import asyncio
2+
from typing import Any, Callable, Dict, List
23

3-
from typing import Any, Dict, List, Callable
4-
5-
from pytest import mark, raises
6-
4+
from graphql.execution import MapAsyncIterator, create_source_event_stream, subscribe
75
from graphql.language import parse
86
from graphql.pyutils import SimplePubSub
97
from graphql.type import (
@@ -16,10 +14,10 @@
1614
GraphQLSchema,
1715
GraphQLString,
1816
)
19-
from graphql.execution import create_source_event_stream, subscribe, MapAsyncIterator
17+
from pytest import mark, raises
2018

2119
try:
22-
anext
20+
anext # type: ignore
2321
except NameError: # pragma: no cover (Python < 3.10)
2422
# noinspection PyShadowingBuiltins
2523
async def anext(iterator):

Diff for: tests/test_user_registry.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515
except ImportError: # Python < 3.7
1616
create_task = None # type: ignore
1717

18-
from pytest import fixture, mark
19-
2018
from graphql import (
21-
graphql,
22-
parse,
23-
subscribe,
2419
GraphQLArgument,
2520
GraphQLBoolean,
2621
GraphQLEnumType,
@@ -33,10 +28,13 @@
3328
GraphQLObjectType,
3429
GraphQLSchema,
3530
GraphQLString,
31+
graphql,
32+
parse,
33+
subscribe,
3634
)
37-
38-
from graphql.pyutils import SimplePubSub, SimplePubSubIterator
3935
from graphql.execution.map_async_iterator import MapAsyncIterator
36+
from graphql.pyutils import SimplePubSub, SimplePubSubIterator
37+
from pytest import fixture, mark
4038

4139

4240
class User(NamedTuple):
@@ -498,22 +496,23 @@ async def mutate_users():
498496
)
499497

500498
async def receive_one():
501-
async for result in subscription_one: # type: ignore # pragma: no cover
499+
async for result in subscription_one: # pragma: no cover
502500
received_one.append(result)
503501
if len(received_one) == 3: # pragma: no cover else
504502
break
505503

506504
async def receive_all():
507-
async for result in subscription_all: # type: ignore # pragma: no cover
505+
async for result in subscription_all: # pragma: no cover
508506
received_all.append(result)
509507
if len(received_all) == 6: # pragma: no cover else
510508
break
511509

512510
tasks = [
513-
create_task(task()) if create_task else task()
511+
create_task(task()) if create_task else task() # type: ignore
514512
for task in (mutate_users, receive_one, receive_all)
515513
]
516514
done, pending = await wait(tasks, timeout=1)
515+
assert len(done) == len(tasks)
517516
assert not pending
518517

519518
expected_data: List[Dict[str, Any]] = [

0 commit comments

Comments
 (0)