From 9931cf6c1b16bf04bba5464693d820f12fba4c21 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:28:59 +0100 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#3752) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Thiago Bellini Ribeiro --- .pre-commit-config.yaml | 2 +- pyproject.toml | 1 + strawberry/codegen/plugins/python.py | 8 ++++---- strawberry/codegen/query_codegen.py | 12 ++++++------ strawberry/exceptions/missing_return_annotation.py | 2 +- .../permission_fail_silently_requires_optional.py | 2 +- strawberry/printer/ast_from_value.py | 3 +-- strawberry/schema/schema_converter.py | 10 ++++------ strawberry/schema/types/scalar.py | 2 +- tests/litestar/test_response_headers.py | 3 +-- tests/schema/test_basic.py | 6 +++--- tests/schema/test_one_of.py | 4 ++-- tests/schema/types/test_datetime.py | 2 +- tests/test_dataloaders.py | 3 +-- 14 files changed, 28 insertions(+), 32 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dd9da78afa..f463fd82c4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.6 + rev: v0.9.1 hooks: - id: ruff-format exclude: ^tests/\w+/snapshots/ diff --git a/pyproject.toml b/pyproject.toml index 1a177b222f..b0666f275c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -257,6 +257,7 @@ ignore = [ "A001", "A002", "A003", + "A005", # Unused arguments "ARG001", diff --git a/strawberry/codegen/plugins/python.py b/strawberry/codegen/plugins/python.py index 7eeb41111d..4af4cb0cbf 100644 --- a/strawberry/codegen/plugins/python.py +++ b/strawberry/codegen/plugins/python.py @@ -65,7 +65,7 @@ def generate_code( def _print_imports(self) -> str: imports = [ - f'from {import_} import {", ".join(sorted(types))}' + f"from {import_} import {', '.join(sorted(types))}" for import_, types in self.imports.items() ] @@ -187,9 +187,9 @@ def _print_scalar_type(self, type_: GraphQLScalar) -> str: if type_.name in self.SCALARS_TO_PYTHON_TYPES: return "" - assert ( - type_.python_type is not None - ), f"Scalar type must have a python type: {type_.name}" + assert type_.python_type is not None, ( + f"Scalar type must have a python type: {type_.name}" + ) return f'{type_.name} = NewType("{type_.name}", {type_.python_type.__name__})' diff --git a/strawberry/codegen/query_codegen.py b/strawberry/codegen/query_codegen.py index 8f0ecffef7..768f334466 100644 --- a/strawberry/codegen/query_codegen.py +++ b/strawberry/codegen/query_codegen.py @@ -347,9 +347,9 @@ def _populate_fragment_types(self, ast: DocumentNode) -> None: ) for fd in fragment_definitions: query_type = self.schema.get_type_by_name(fd.type_condition.name.value) - assert isinstance( - query_type, StrawberryObjectDefinition - ), f"{fd.type_condition.name.value!r} is not a type in the graphql schema!" + assert isinstance(query_type, StrawberryObjectDefinition), ( + f"{fd.type_condition.name.value!r} is not a type in the graphql schema!" + ) typename = fd.type_condition.name.value graph_ql_object_type_factory = partial( @@ -695,9 +695,9 @@ def _field_from_selection_set( selection.name.value, parent_type_name ) - assert ( - selected_field - ), f"Couldn't find {parent_type_name}.{selection.name.value}" + assert selected_field, ( + f"Couldn't find {parent_type_name}.{selection.name.value}" + ) selected_field_type, wrapper = self._unwrap_type(selected_field.type) name = capitalize_first(to_camel_case(selection.name.value)) diff --git a/strawberry/exceptions/missing_return_annotation.py b/strawberry/exceptions/missing_return_annotation.py index 60d64bffa0..4b863c84f7 100644 --- a/strawberry/exceptions/missing_return_annotation.py +++ b/strawberry/exceptions/missing_return_annotation.py @@ -27,7 +27,7 @@ def __init__( "did you forget to add it?" ) self.rich_message = ( - "[bold red]Missing annotation for field " f"`[underline]{resolver.name}[/]`" + f"[bold red]Missing annotation for field `[underline]{resolver.name}[/]`" ) self.suggestion = ( diff --git a/strawberry/exceptions/permission_fail_silently_requires_optional.py b/strawberry/exceptions/permission_fail_silently_requires_optional.py index ca3a7de713..16bb1494cf 100644 --- a/strawberry/exceptions/permission_fail_silently_requires_optional.py +++ b/strawberry/exceptions/permission_fail_silently_requires_optional.py @@ -16,7 +16,7 @@ class PermissionFailSilentlyRequiresOptionalError(StrawberryException): def __init__(self, field: StrawberryField) -> None: self.field = field self.message = ( - "Cannot use fail_silently=True with a non-optional " "or non-list field" + "Cannot use fail_silently=True with a non-optional or non-list field" ) self.rich_message = ( "fail_silently permissions can only be used with fields of type " diff --git a/strawberry/printer/ast_from_value.py b/strawberry/printer/ast_from_value.py index eb2da54853..d4e23294ca 100644 --- a/strawberry/printer/ast_from_value.py +++ b/strawberry/printer/ast_from_value.py @@ -56,8 +56,7 @@ def ast_from_leaf_type( return IntValueNode(value=str(serialized)) if isinstance(serialized, float) and isfinite(serialized): value = str(serialized) - if value.endswith(".0"): - value = value[:-2] + value = value.removesuffix(".0") return FloatValueNode(value=value) if isinstance(serialized, str): diff --git a/strawberry/schema/schema_converter.py b/strawberry/schema/schema_converter.py index 000d384934..332a9bdb5f 100644 --- a/strawberry/schema/schema_converter.py +++ b/strawberry/schema/schema_converter.py @@ -518,12 +518,10 @@ def from_interface( assert isinstance(graphql_interface, GraphQLInterfaceType) # For mypy return graphql_interface - def _get_resolve_type() -> ( - Callable[ - [Any, GraphQLResolveInfo, GraphQLAbstractType], - Union[Awaitable[Optional[str]], str, None], - ] - ): + def _get_resolve_type() -> Callable[ + [Any, GraphQLResolveInfo, GraphQLAbstractType], + Union[Awaitable[Optional[str]], str, None], + ]: if interface.resolve_type: return interface.resolve_type diff --git a/strawberry/schema/types/scalar.py b/strawberry/schema/types/scalar.py index f8a2982405..a8f5765244 100644 --- a/strawberry/schema/types/scalar.py +++ b/strawberry/schema/types/scalar.py @@ -68,7 +68,7 @@ def _get_scalar_definition(scalar: type) -> ScalarDefinition: GlobalID, name="GlobalID", description=GraphQLID.description, - parse_literal=lambda v, vars=None: GlobalID.from_id( + parse_literal=lambda v, vars=None: GlobalID.from_id( # noqa: A006 GraphQLID.parse_literal(v, vars) ), parse_value=GlobalID.from_id, diff --git a/tests/litestar/test_response_headers.py b/tests/litestar/test_response_headers.py index a606e9ad03..7a70045841 100644 --- a/tests/litestar/test_response_headers.py +++ b/tests/litestar/test_response_headers.py @@ -59,6 +59,5 @@ def abc(self, info: strawberry.Info) -> str: assert response.json() == {"data": {"abc": "abc"}} assert response.headers["set-cookie"] == ( - "strawberry=rocks; Path=/; SameSite=lax, " - "Litestar=rocks; Path=/; SameSite=lax" + "strawberry=rocks; Path=/; SameSite=lax, Litestar=rocks; Path=/; SameSite=lax" ) diff --git a/tests/schema/test_basic.py b/tests/schema/test_basic.py index 1f63c86084..77cbf5605b 100644 --- a/tests/schema/test_basic.py +++ b/tests/schema/test_basic.py @@ -476,9 +476,9 @@ class Query: } """ assert str(schema) == textwrap.dedent(expected).strip() - assert " list[int]: with pytest.raises( WrongNumberOfResultsReturned, match=( - "Received wrong number of results in dataloader, " - "expected: 1, received: 2" + "Received wrong number of results in dataloader, expected: 1, received: 2" ), ): await loader.load(1)