Skip to content

Commit 5855dfc

Browse files
committed
Update mypy and check tests
1 parent eeaf9ce commit 5855dfc

Some content is hidden

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

59 files changed

+224
-223
lines changed

.mypy.ini

Lines changed: 0 additions & 2 deletions
This file was deleted.

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ include .bumpversion.cfg
88
include .coveragerc
99
include .editorconfig
1010
include .flake8
11-
include .mypy.ini
1211

1312
include codecov.yml
13+
include mypy.ini
1414
include tox.ini
1515

1616
include poetry.lock

mypy.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[mypy]
2+
python_version = 3.7
3+
warn_redundant_casts = true
4+
warn_unused_ignores = True
5+
# https://github.com/python/mypy/issues/7203
6+
new_semantic_analyzer = False

poetry.lock

Lines changed: 29 additions & 7 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
@@ -36,7 +36,7 @@ pytest-describe = ">=0.12"
3636
pyyaml = "^5.1"
3737
black = ">=19.3b0"
3838
flake8 = "^3.7"
39-
mypy = ">=0.711"
39+
mypy = ">=0.720"
4040
codecov = "^2"
4141
sphinx = "^2.1"
4242
sphinx_rtd_theme = ">=0.4"

src/graphql/subscription/subscribe.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ async def subscribe(
6262
return ExecutionResult(data=None, errors=[error])
6363
if isinstance(result_or_stream, ExecutionResult):
6464
return result_or_stream
65-
result_or_stream = cast(AsyncIterable, result_or_stream)
6665

6766
async def map_source_to_response(payload):
6867
"""Map source to response.
@@ -153,7 +152,6 @@ async def create_source_event_stream(
153152
# Call the `subscribe()` resolver or the default resolver to produce an
154153
# AsyncIterable yielding raw payloads.
155154
resolve_fn = field_def.subscribe or context.field_resolver
156-
resolve_fn = cast(GraphQLFieldResolver, resolve_fn) # help mypy
157155

158156
path = add_path(None, response_name)
159157

@@ -172,7 +170,7 @@ async def create_source_event_stream(
172170

173171
# Assert field returned an event stream, otherwise yield an error.
174172
if isinstance(event_stream, AsyncIterable):
175-
return cast(AsyncIterable, event_stream)
173+
return event_stream
176174
raise TypeError(
177175
f"Subscription field must return AsyncIterable. Received: {event_stream!r}"
178176
)

src/graphql/type/definition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def __init__(
449449
)
450450
else:
451451
args = {
452-
name: cast(GraphQLArgument, value)
452+
name: value
453453
if isinstance(value, GraphQLArgument)
454454
else GraphQLArgument(cast(GraphQLInputType, value))
455455
for name, value in args.items()

src/graphql/type/directives.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(
7575
)
7676
else:
7777
args = {
78-
name: cast(GraphQLArgument, value)
78+
name: value
7979
if isinstance(value, GraphQLArgument)
8080
else GraphQLArgument(cast(GraphQLInputType, value))
8181
for name, value in args.items()

src/graphql/utilities/ast_from_value.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ def ast_from_value(value: Any, type_: GraphQLInputType) -> Optional[ValueNode]:
7171
type_ = cast(GraphQLList, type_)
7272
item_type = type_.of_type
7373
if isinstance(value, Iterable) and not isinstance(value, str):
74-
value_nodes = [
75-
ast_from_value(item, item_type) for item in value # type: ignore
76-
]
74+
value_nodes = [ast_from_value(item, item_type) for item in value]
7775
return ListValueNode(values=value_nodes)
78-
return ast_from_value(value, item_type) # type: ignore
76+
return ast_from_value(value, item_type)
7977

8078
# Populate the fields of the input object by creating ASTs from each value in the
8179
# Python dict according to the fields in the input type.

src/graphql/utilities/build_ast_schema.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,13 @@ def build_ast_schema(
103103
if isinstance(def_, SchemaDefinitionNode):
104104
schema_def = def_
105105
elif isinstance(def_, TypeDefinitionNode):
106-
def_ = cast(TypeDefinitionNode, def_)
107106
type_defs.append(def_)
108107
elif isinstance(def_, DirectiveDefinitionNode):
109108
append_directive_def(def_)
110109

111110
def resolve_type(type_name: str) -> GraphQLNamedType:
112111
type_ = type_map.get(type_name)
113-
if not type:
112+
if not type_:
114113
raise TypeError(f"Type '{type_name}' not found in document.")
115114
return type_
116115

0 commit comments

Comments
 (0)