Skip to content

Commit

Permalink
Update ruff and adapt code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Sep 7, 2024
1 parent 4933704 commit 448d045
Show file tree
Hide file tree
Showing 54 changed files with 258 additions and 212 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ tox = [
optional = true

[tool.poetry.group.lint.dependencies]
ruff = ">=0.5.7,<0.6"
ruff = ">=0.6.4,<0.7"
mypy = [
{ version = "^1.11", python = ">=3.8" },
{ version = "~1.4", python = "<3.8" }
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/execution/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
anext # noqa: B018
except NameError: # pragma: no cover (Python < 3.10)
# noinspection PyShadowingBuiltins
async def anext(iterator: AsyncIterator) -> Any: # noqa: A001
async def anext(iterator: AsyncIterator) -> Any:
"""Return the next item from an async iterator."""
return await iterator.__anext__()

Expand Down
3 changes: 1 addition & 2 deletions src/graphql/pyutils/suggestion_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ def measure(self, option: str, threshold: int) -> int | None:
double_diagonal_cell = rows[(i - 2) % 3][j - 2]
current_cell = min(current_cell, double_diagonal_cell + 1)

if current_cell < smallest_cell:
smallest_cell = current_cell
smallest_cell = min(current_cell, smallest_cell)

current_row[j] = current_cell

Expand Down
1 change: 1 addition & 0 deletions tests/execution/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any, NamedTuple

import pytest

from graphql.execution import ExecutionResult, execute, execute_sync
from graphql.language import parse
from graphql.pyutils import is_awaitable
Expand Down
7 changes: 4 additions & 3 deletions tests/execution/test_customize.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from inspect import isasyncgen

import pytest

from graphql.execution import ExecutionContext, execute, subscribe
from graphql.language import parse
from graphql.type import GraphQLField, GraphQLObjectType, GraphQLSchema, GraphQLString
Expand All @@ -9,7 +10,7 @@
anext # noqa: B018
except NameError: # pragma: no cover (Python < 3.10)
# noinspection PyShadowingBuiltins
async def anext(iterator): # noqa: A001
async def anext(iterator):
"""Return the next item from an async iterator."""
return await iterator.__anext__()

Expand Down Expand Up @@ -62,7 +63,7 @@ def execute_field(


def describe_customize_subscription():
@pytest.mark.asyncio()
@pytest.mark.asyncio
async def uses_a_custom_subscribe_field_resolver():
schema = GraphQLSchema(
query=GraphQLObjectType("Query", {"foo": GraphQLField(GraphQLString)}),
Expand Down Expand Up @@ -91,7 +92,7 @@ async def custom_foo():

await subscription.aclose()

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def uses_a_custom_execution_context_class():
class TestExecutionContext(ExecutionContext):
def build_resolve_info(self, *args, **kwargs):
Expand Down
39 changes: 20 additions & 19 deletions tests/execution/test_defer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any, AsyncGenerator, NamedTuple

import pytest

from graphql.error import GraphQLError
from graphql.execution import (
ExecutionResult,
Expand Down Expand Up @@ -333,7 +334,7 @@ def can_print_deferred_fragment_record():
"path=['bar'], label='foo', parent_context, data)"
)

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def can_defer_fragments_containing_scalar_types():
document = parse(
"""
Expand All @@ -358,7 +359,7 @@ async def can_defer_fragments_containing_scalar_types():
},
]

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def can_disable_defer_using_if_argument():
document = parse(
"""
Expand All @@ -384,7 +385,7 @@ async def can_disable_defer_using_if_argument():
},
}

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def does_not_disable_defer_with_null_if_argument():
document = parse(
"""
Expand All @@ -409,7 +410,7 @@ async def does_not_disable_defer_with_null_if_argument():
},
]

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def throws_an_error_for_defer_directive_with_non_string_label():
document = parse(
"""
Expand All @@ -430,7 +431,7 @@ async def throws_an_error_for_defer_directive_with_non_string_label():
],
}

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def can_defer_fragments_on_the_top_level_query_field():
document = parse(
"""
Expand All @@ -456,7 +457,7 @@ async def can_defer_fragments_on_the_top_level_query_field():
},
]

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def can_defer_fragments_with_errors_on_the_top_level_query_field():
document = parse(
"""
Expand Down Expand Up @@ -493,7 +494,7 @@ async def can_defer_fragments_with_errors_on_the_top_level_query_field():
},
]

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def can_defer_a_fragment_within_an_already_deferred_fragment():
document = parse(
"""
Expand Down Expand Up @@ -540,7 +541,7 @@ async def can_defer_a_fragment_within_an_already_deferred_fragment():
},
]

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def can_defer_a_fragment_that_is_also_not_deferred_with_deferred_first():
document = parse(
"""
Expand Down Expand Up @@ -571,7 +572,7 @@ async def can_defer_a_fragment_that_is_also_not_deferred_with_deferred_first():
},
]

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def can_defer_a_fragment_that_is_also_not_deferred_with_non_deferred_first():
document = parse(
"""
Expand Down Expand Up @@ -602,7 +603,7 @@ async def can_defer_a_fragment_that_is_also_not_deferred_with_non_deferred_first
},
]

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def can_defer_an_inline_fragment():
document = parse(
"""
Expand Down Expand Up @@ -632,7 +633,7 @@ async def can_defer_an_inline_fragment():
},
]

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def handles_errors_thrown_in_deferred_fragments():
document = parse(
"""
Expand Down Expand Up @@ -669,7 +670,7 @@ async def handles_errors_thrown_in_deferred_fragments():
},
]

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def handles_non_nullable_errors_thrown_in_deferred_fragments():
document = parse(
"""
Expand Down Expand Up @@ -709,7 +710,7 @@ async def handles_non_nullable_errors_thrown_in_deferred_fragments():
},
]

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def handles_non_nullable_errors_thrown_outside_deferred_fragments():
document = parse(
"""
Expand Down Expand Up @@ -740,7 +741,7 @@ async def handles_non_nullable_errors_thrown_outside_deferred_fragments():
],
}

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def handles_async_non_nullable_errors_thrown_in_deferred_fragments():
document = parse(
"""
Expand Down Expand Up @@ -780,7 +781,7 @@ async def handles_async_non_nullable_errors_thrown_in_deferred_fragments():
},
]

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def returns_payloads_in_correct_order():
document = parse(
"""
Expand Down Expand Up @@ -833,7 +834,7 @@ async def returns_payloads_in_correct_order():
},
]

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def returns_payloads_from_synchronous_data_in_correct_order():
document = parse(
"""
Expand Down Expand Up @@ -886,7 +887,7 @@ async def returns_payloads_from_synchronous_data_in_correct_order():
},
]

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def filters_deferred_payloads_when_list_item_from_async_iterable_nulled():
document = parse(
"""
Expand Down Expand Up @@ -920,7 +921,7 @@ async def filters_deferred_payloads_when_list_item_from_async_iterable_nulled():
],
}

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def original_execute_function_throws_error_if_deferred_and_all_is_sync():
document = parse(
"""
Expand All @@ -938,7 +939,7 @@ async def original_execute_function_throws_error_if_deferred_and_all_is_sync():
" multiple payloads (due to @defer or @stream directive)"
)

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def original_execute_function_throws_error_if_deferred_and_not_all_is_sync():
document = parse(
"""
Expand Down
1 change: 1 addition & 0 deletions tests/execution/test_execution_result.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from graphql.error import GraphQLError
from graphql.execution import ExecutionResult

Expand Down
9 changes: 5 additions & 4 deletions tests/execution/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any, Awaitable, cast

import pytest

from graphql.error import GraphQLError
from graphql.execution import execute, execute_sync
from graphql.language import FieldNode, OperationDefinitionNode, parse
Expand Down Expand Up @@ -41,7 +42,7 @@ def accepts_positional_arguments():

assert result == ({"a": "rootValue"}, None)

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def executes_arbitrary_code():
# noinspection PyMethodMayBeStatic,PyMethodMayBeStatic
class Data:
Expand Down Expand Up @@ -375,7 +376,7 @@ def resolve(_obj, _info, **args):
assert len(resolved_args) == 1
assert resolved_args[0] == {"numArg": 123, "stringArg": "foo"}

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def nulls_out_error_subtrees():
document = parse(
"""
Expand Down Expand Up @@ -868,7 +869,7 @@ def resolves_to_an_error_if_schema_does_not_support_operation():
],
)

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def correct_field_ordering_despite_execution_order():
schema = GraphQLSchema(
GraphQLObjectType(
Expand Down Expand Up @@ -984,7 +985,7 @@ def does_not_include_arguments_that_were_not_set():
None,
)

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def fails_when_is_type_of_check_is_not_met():
class Special:
value: str
Expand Down
Loading

0 comments on commit 448d045

Please sign in to comment.