Skip to content

Commit 8158da5

Browse files
committed
Update mypy, use new semantic analyzer (#67)
1 parent 07a4cfa commit 8158da5

28 files changed

+194
-138
lines changed

mypy.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ python_version = 3.8
33
check_untyped_defs = True
44
warn_redundant_casts = True
55
warn_unused_ignores = True
6-
# https://github.com/python/mypy/issues/7203
7-
new_semantic_analyzer = False

poetry.lock

Lines changed: 30 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pytest-describe = ">=0.12"
4040
pyyaml = "^5.1"
4141
black = ">=19.10b0"
4242
flake8 = "^3.7"
43-
mypy = ">=0.720,<0.730"
43+
mypy = ">=0.750,<0.760"
4444
codecov = "^2"
4545
sphinx = "^2.2"
4646
sphinx_rtd_theme = ">=0.4"

src/graphql/execution/execute.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
FrozenList,
3535
Path,
3636
)
37-
from ..utilities import get_operation_root_type, type_from_ast
37+
from ..utilities.get_operation_root_type import get_operation_root_type
38+
from ..utilities.type_from_ast import type_from_ast
3839
from ..type import (
3940
GraphQLAbstractType,
4041
GraphQLField,

src/graphql/execution/values.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
is_input_type,
2424
is_non_null_type,
2525
)
26-
from ..utilities import coerce_input_value, type_from_ast, value_from_ast
26+
from ..utilities.coerce_input_value import coerce_input_value
27+
from ..utilities.type_from_ast import type_from_ast
28+
from ..utilities.value_from_ast import value_from_ast
2729

2830
__all__ = ["get_variable_values", "get_argument_values", "get_directive_values"]
2931

src/graphql/language/ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def __init_subclass__(cls):
239239
keys: List[str] = []
240240
for base in cls.__bases__:
241241
# noinspection PyUnresolvedReferences
242-
keys.extend(base.keys)
242+
keys.extend(base.keys) # type: ignore
243243
keys.extend(cls.__slots__)
244244
cls.keys = keys
245245

src/graphql/language/visitor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Callable,
66
List,
77
NamedTuple,
8+
Optional,
89
Sequence,
910
Tuple,
1011
Union,
@@ -157,8 +158,11 @@ def __init_subclass__(cls):
157158
for attr, val in cls.__dict__.items():
158159
if attr.startswith("_"):
159160
continue
160-
attr = attr.split("_", 1)
161-
attr, kind = attr if len(attr) > 1 else (attr[0], None)
161+
attr_kind = attr.split("_", 1)
162+
if len(attr_kind) < 2:
163+
kind: Optional[str] = None
164+
else:
165+
attr, kind = attr_kind
162166
if attr in ("enter", "leave"):
163167
if kind:
164168
name = snake_to_camel(kind) + "Node"

src/graphql/subscription/map_async_iterator.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from asyncio import Event, ensure_future, wait
1+
from asyncio import Event, ensure_future, Future, wait
22
from concurrent.futures import FIRST_COMPLETED
33
from inspect import isasyncgen, isawaitable
4-
from typing import AsyncIterable, Callable
4+
from typing import AsyncIterable, Callable, Set
55

66
__all__ = ["MapAsyncIterator"]
77

@@ -42,7 +42,9 @@ async def __anext__(self):
4242
aclose = ensure_future(self._close_event.wait())
4343
anext = ensure_future(self.iterator.__anext__())
4444

45-
done, pending = await wait([aclose, anext], return_when=FIRST_COMPLETED)
45+
pending: Set[Future] = (
46+
await wait([aclose, anext], return_when=FIRST_COMPLETED)
47+
)[1]
4648
for task in pending:
4749
task.cancel()
4850

src/graphql/subscription/subscribe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def subscribe(
6262
if isinstance(result_or_stream, ExecutionResult):
6363
return result_or_stream
6464

65-
async def map_source_to_response(payload):
65+
async def map_source_to_response(payload) -> ExecutionResult:
6666
"""Map source to response.
6767
6868
For each payload yielded from a subscription, map it over the normal GraphQL
@@ -81,7 +81,7 @@ async def map_source_to_response(payload):
8181
operation_name,
8282
field_resolver,
8383
)
84-
return await result if isawaitable(result) else result
84+
return await result if isawaitable(result) else result # type: ignore
8585

8686
return MapAsyncIterator(result_or_stream, map_source_to_response)
8787

src/graphql/type/definition.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,11 @@ def __init__(
361361
" as a sequence of ScalarTypeExtensionNode instances."
362362
)
363363
if serialize is not None:
364-
self.serialize = serialize
364+
self.serialize = serialize # type: ignore
365365
if parse_value is not None:
366-
self.parse_value = parse_value
366+
self.parse_value = parse_value # type: ignore
367367
if parse_literal is not None:
368-
self.parse_literal = parse_literal
368+
self.parse_literal = parse_literal # type: ignore
369369

370370
def __repr__(self):
371371
return f"<{self.__class__.__name__} {self.name!r}>"
@@ -391,9 +391,7 @@ def parse_value(value: Any) -> Any:
391391
"""
392392
return value
393393

394-
def parse_literal( # type: ignore
395-
self, node: ValueNode, _variables: Dict[str, Any] = None
396-
) -> Any:
394+
def parse_literal(self, node: ValueNode, _variables: Dict[str, Any] = None) -> Any:
397395
"""Parses an externally provided literal value to use as an input.
398396
399397
This default method uses the parse_value method and should be replaced
@@ -1247,7 +1245,7 @@ def __init__(
12471245
)
12481246
self._fields = fields
12491247
if out_type is not None:
1250-
self.out_type = out_type
1248+
self.out_type = out_type # type: ignore
12511249

12521250
@staticmethod
12531251
def out_type(value: Dict[str, Any]) -> Any:

0 commit comments

Comments
 (0)