diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 76dc5460f5..0000000000 --- a/.flake8 +++ /dev/null @@ -1,19 +0,0 @@ -[flake8] -max-line-length = 89 -exclude=.venv,.git,tests/codegen/snapshots,dist,build,__pycache__ -ignore = W503 -extend-ignore = - # See https://github.com/PyCQA/pycodestyle/issues/373 - E203, - -per-file-ignores = - tests/types/test_lazy_types.py:E800 - tests/test_forward_references.py:E800 - tests/schema/test_resolvers.py:E800 - tests/types/test_string_annotations.py:E800 - tests/federation/printer/*:E501 - tests/pyright/test_federation.py:E501 - tests/federation/test_printer.py:E800 - tests/federation/test_printer.py:E501 - tests/test_printer/test_basic.py:E501 - tests/test_printer/test_schema_directives.py:E501 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4ce157cbcc..f1d4e539d1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,33 +1,14 @@ repos: - - repo: https://github.com/PyCQA/autoflake - rev: 'v1.7.7' - hooks: - - id: autoflake - args: ['--in-place', '--remove-all-unused-imports', '--ignore-init-module-imports'] - name: autoflake - entry: autoflake - language: python - 'types': [python] - require_serial: true - exclude: ^tests/codegen/snapshots/python/ - - repo: https://github.com/asottile/pyupgrade - rev: v3.2.2 + rev: v3.2.3 hooks: - id: pyupgrade args: [--py37-plus, --keep-runtime-typing] - - repo: https://github.com/PyCQA/flake8 - rev: 5.0.4 - hooks: - - id: flake8 - additional_dependencies: ["flake8-eradicate==1.3.0"] - exclude: ^tests/codegen/snapshots/python/ - - - repo: https://github.com/pycqa/isort - rev: 5.10.1 + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.0.149 hooks: - - id: isort + - id: ruff exclude: ^tests/codegen/snapshots/python/ - repo: https://github.com/patrick91/pre-commit-alex @@ -43,7 +24,7 @@ repos: files: '^docs/.*\.mdx?$' - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 hooks: - id: trailing-whitespace - id: check-merge-conflict diff --git a/pyproject.toml b/pyproject.toml index f10cd31a69..afb4434a34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,7 @@ include = ["strawberry/py.typed"] [tool.poetry.urls] "Discord" = "https://discord.com/invite/3uQ2PaY" "Twitter" = "https://twitter.com/strawberry_gql" +"Mastodon" = "https://farbun.social/@strawberry" "Sponsor on GitHub" = "https://github.com/sponsors/strawberry-graphql" "Sponsor on Open Collective" = "https://opencollective.com/strawberry-graphql" @@ -129,19 +130,6 @@ extend-exclude = ''' tests/codegen/snapshots/ ''' -[tool.isort] -src_paths = ["strawberry", "tests", "scripts"] -profile = "black" -indent = 4 -combine_star = true -combine_as_imports = true -lines_after_imports = 2 -known_django = ["django"] -known_graphql = ["graphql"] -known_pytest = ["pytest"] -known_first_party = ["strawberry"] -sections = ["FUTURE", "STDLIB", "PYTEST", "THIRDPARTY", "DJANGO", "GRAPHQL", "FIRSTPARTY", "LOCALFOLDER"] - [tool.pytest.ini_options] addopts = "-s --emoji --mypy-ini-file=mypy.ini --benchmark-disable" DJANGO_SETTINGS_MODULE = "tests.django.django_settings" @@ -166,3 +154,54 @@ reportMissingImports = true reportMissingTypeStubs = false pythonVersion = "3.7" stubPath = "" + +[tool.ruff] +line-length = 88 +select = ["E", "F", "ERA", "I"] +ignore = ["I252"] +fix = true +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "venv", + "tests/codegen/snapshots" +] +src = ["strawberry", "tests"] + +[tool.ruff.per-file-ignores] +"tests/federation/printer/*" = ["E501"] +"tests/test_printer/test_basic.py" = ["E501"] +"tests/pyright/test_federation.py" = ["E501"] +"tests/test_printer/test_schema_directives.py" = ["E501"] +# temporary until https://github.com/charliermarsh/ruff/issues/960 is fixed +"tests/federation/printer/test_entities.py" = ["F821"] +"tests/federation/printer/test_keys.py" = ["F821"] +"tests/federation/printer/test_provides.py" = ["F821"] +"tests/schema/test_resolvers.py" = ["F821"] +"tests/test_forward_references.py" = ["F821"] +"tests/types/resolving/test_string_annotations.py" = ["F821"] +"tests/types/test_argument_types.py" = ["F821"] +"tests/types/test_object_types.py" = ["F821"] +"tests/types/test_resolver_types.py" = ["F821"] +"tests/federation/printer/test_requires.py" = ["F821"] + +[tool.ruff.isort] +known-first-party = ["strawberry"] +known-third-party = ["django", "graphql"] +extra-standard-library = ["typing_extensions"] diff --git a/strawberry/aiohttp/handlers/http_handler.py b/strawberry/aiohttp/handlers/http_handler.py index f6d4934c07..6d1a1e724c 100644 --- a/strawberry/aiohttp/handlers/http_handler.py +++ b/strawberry/aiohttp/handlers/http_handler.py @@ -1,7 +1,6 @@ import json from io import BytesIO from typing import Any, Dict, Union - from typing_extensions import Literal from aiohttp import web diff --git a/strawberry/annotation.py b/strawberry/annotation.py index e6e5e8dc97..063084c43e 100644 --- a/strawberry/annotation.py +++ b/strawberry/annotation.py @@ -12,7 +12,6 @@ Union, _eval_type, ) - from typing_extensions import Annotated, Self, get_args, get_origin from strawberry.exceptions import StrawberryException @@ -319,7 +318,8 @@ def _is_union(cls, annotation: Any) -> bool: if isinstance(annotation, UnionType): return True - # unions declared as Union[A, B] fall through to this check, even on python 3.10+ + # unions declared as Union[A, B] fall through to this check + # even on python 3.10+ annotation_origin = getattr(annotation, "__origin__", None) diff --git a/strawberry/arguments.py b/strawberry/arguments.py index db7845eca4..ac7fc79f51 100644 --- a/strawberry/arguments.py +++ b/strawberry/arguments.py @@ -13,7 +13,6 @@ Union, cast, ) - from typing_extensions import Annotated, get_args, get_origin from strawberry.annotation import StrawberryAnnotation @@ -25,7 +24,8 @@ from .exceptions import MultipleStrawberryArgumentsError, UnsupportedTypeError from .scalars import is_scalar from .types.types import TypeDefinition -from .unset import UNSET as _deprecated_UNSET, _deprecated_is_unset # noqa +from .unset import UNSET as _deprecated_UNSET +from .unset import _deprecated_is_unset # noqa if TYPE_CHECKING: diff --git a/strawberry/asgi/test/client.py b/strawberry/asgi/test/client.py index f4f8d87814..3fc7760727 100644 --- a/strawberry/asgi/test/client.py +++ b/strawberry/asgi/test/client.py @@ -1,6 +1,5 @@ import json from typing import Dict, Mapping, Optional - from typing_extensions import Literal from strawberry.test import BaseGraphQLTestClient diff --git a/strawberry/auto.py b/strawberry/auto.py index 4b36dc7e0d..f4b6f63a3a 100644 --- a/strawberry/auto.py +++ b/strawberry/auto.py @@ -1,7 +1,6 @@ from __future__ import annotations from typing import Any, Optional, Union, cast - from typing_extensions import Annotated, get_args, get_origin from strawberry.type import StrawberryType diff --git a/strawberry/chalice/views.py b/strawberry/chalice/views.py index 628fa44280..941a5cf2de 100644 --- a/strawberry/chalice/views.py +++ b/strawberry/chalice/views.py @@ -45,8 +45,10 @@ def get_root_value(self, request: Request) -> Optional[object]: @staticmethod def render_graphiql() -> str: """ - Returns a string containing the html for the graphiql webpage. It also caches the - result using lru cache. This saves loading from disk each time it is invoked. + Returns a string containing the html for the graphiql webpage. It also caches + the result using lru cache. + This saves loading from disk each time it is invoked. + Returns: The GraphiQL html page as a string """ diff --git a/strawberry/channels/handlers/base.py b/strawberry/channels/handlers/base.py index 1b5fdb4a10..a82035c8e8 100644 --- a/strawberry/channels/handlers/base.py +++ b/strawberry/channels/handlers/base.py @@ -12,7 +12,6 @@ Optional, Sequence, ) - from typing_extensions import Literal, Protocol, TypedDict from channels.consumer import AsyncConsumer diff --git a/strawberry/codegen/query_codegen.py b/strawberry/codegen/query_codegen.py index c51778140e..b9aa6cb767 100644 --- a/strawberry/codegen/query_codegen.py +++ b/strawberry/codegen/query_codegen.py @@ -3,7 +3,6 @@ from dataclasses import dataclass from pathlib import Path from typing import Callable, Iterable, List, Optional, Tuple, Type, Union, cast - from typing_extensions import Literal, Protocol from graphql import ( diff --git a/strawberry/codegen/types.py b/strawberry/codegen/types.py index 95f348af41..31cb151659 100644 --- a/strawberry/codegen/types.py +++ b/strawberry/codegen/types.py @@ -3,7 +3,6 @@ from dataclasses import dataclass from enum import EnumMeta from typing import List, Optional, Type, Union - from typing_extensions import Literal diff --git a/strawberry/directive.py b/strawberry/directive.py index 7e88836a47..b08343d075 100644 --- a/strawberry/directive.py +++ b/strawberry/directive.py @@ -3,7 +3,6 @@ import dataclasses import inspect from typing import Any, Callable, List, Optional, TypeVar - from typing_extensions import Annotated from graphql import DirectiveLocation diff --git a/strawberry/experimental/pydantic/conversion_types.py b/strawberry/experimental/pydantic/conversion_types.py index b0543b5eb3..4d442b313e 100644 --- a/strawberry/experimental/pydantic/conversion_types.py +++ b/strawberry/experimental/pydantic/conversion_types.py @@ -1,9 +1,9 @@ from __future__ import annotations from typing import Any, Dict, Optional, TypeVar +from typing_extensions import Protocol from pydantic import BaseModel -from typing_extensions import Protocol from strawberry.types.types import TypeDefinition diff --git a/strawberry/experimental/pydantic/object_type.py b/strawberry/experimental/pydantic/object_type.py index 6c5322081e..ae44f93f7e 100644 --- a/strawberry/experimental/pydantic/object_type.py +++ b/strawberry/experimental/pydantic/object_type.py @@ -16,9 +16,8 @@ cast, ) -from pydantic.fields import ModelField - from graphql import GraphQLResolveInfo +from pydantic.fields import ModelField from strawberry.annotation import StrawberryAnnotation from strawberry.auto import StrawberryAuto diff --git a/strawberry/experimental/pydantic/utils.py b/strawberry/experimental/pydantic/utils.py index fd9bd71f49..88b71f878c 100644 --- a/strawberry/experimental/pydantic/utils.py +++ b/strawberry/experimental/pydantic/utils.py @@ -66,7 +66,8 @@ def get_default_factory_for_field( """ Gets the default factory for a pydantic field. - Handles mutable defaults when making the dataclass by using pydantic's smart_deepcopy + Handles mutable defaults when making the dataclass by + using pydantic's smart_deepcopy Returns optionally a NoArgAnyCallable representing a default_factory parameter """ diff --git a/strawberry/ext/mypy_plugin.py b/strawberry/ext/mypy_plugin.py index c9da146fd9..89e438e427 100644 --- a/strawberry/ext/mypy_plugin.py +++ b/strawberry/ext/mypy_plugin.py @@ -2,7 +2,6 @@ import warnings from decimal import Decimal from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union, cast - from typing_extensions import Final import mypy @@ -70,7 +69,8 @@ # To be compatible with user who don't use pydantic try: - from pydantic.mypy import METADATA_KEY as PYDANTIC_METADATA_KEY, PydanticModelField + from pydantic.mypy import METADATA_KEY as PYDANTIC_METADATA_KEY + from pydantic.mypy import PydanticModelField except ImportError: PYDANTIC_METADATA_KEY = "" diff --git a/strawberry/extensions/query_depth_limiter.py b/strawberry/extensions/query_depth_limiter.py index 7129904d2c..e08a26fe6f 100644 --- a/strawberry/extensions/query_depth_limiter.py +++ b/strawberry/extensions/query_depth_limiter.py @@ -163,7 +163,8 @@ def determine_depth( return depth_so_far if isinstance(node, FieldNode): - # by default, ignore the introspection fields which begin with double underscores + # by default, ignore the introspection fields which begin + # with double underscores should_ignore = is_introspection_key(node.name.value) or is_ignored( node, ignore ) diff --git a/strawberry/extensions/tracing/opentelemetry.py b/strawberry/extensions/tracing/opentelemetry.py index 1976afd778..b21cd38dd9 100644 --- a/strawberry/extensions/tracing/opentelemetry.py +++ b/strawberry/extensions/tracing/opentelemetry.py @@ -3,11 +3,10 @@ from inspect import isawaitable from typing import Any, Callable, Dict, Optional +from graphql import GraphQLResolveInfo from opentelemetry import trace from opentelemetry.trace import Span, SpanKind, Tracer -from graphql import GraphQLResolveInfo - from strawberry.extensions import Extension from strawberry.extensions.utils import get_path_from_info from strawberry.types.execution import ExecutionContext diff --git a/strawberry/federation/enum.py b/strawberry/federation/enum.py index 9e65341502..0d7f51911f 100644 --- a/strawberry/federation/enum.py +++ b/strawberry/federation/enum.py @@ -1,11 +1,7 @@ from typing import Any, Callable, Iterable, Optional, Union, overload -from strawberry.enum import ( - EnumType, - EnumValueDefinition, - _process_enum, - enum_value as base_enum_value, -) +from strawberry.enum import EnumType, EnumValueDefinition, _process_enum +from strawberry.enum import enum_value as base_enum_value def enum_value( diff --git a/strawberry/federation/field.py b/strawberry/federation/field.py index f3cbe52442..2fa355126d 100644 --- a/strawberry/federation/field.py +++ b/strawberry/federation/field.py @@ -11,10 +11,10 @@ Union, overload, ) - from typing_extensions import Literal -from strawberry.field import _RESOLVER_TYPE, StrawberryField, field as base_field +from strawberry.field import _RESOLVER_TYPE, StrawberryField +from strawberry.field import field as base_field from strawberry.permission import BasePermission from strawberry.unset import UNSET diff --git a/strawberry/federation/object_type.py b/strawberry/federation/object_type.py index 8d4e406101..2677472dde 100644 --- a/strawberry/federation/object_type.py +++ b/strawberry/federation/object_type.py @@ -10,7 +10,8 @@ overload, ) -from strawberry.field import StrawberryField, field as base_field +from strawberry.field import StrawberryField +from strawberry.field import field as base_field from strawberry.object_type import type as base_type from strawberry.unset import UNSET from strawberry.utils.typing import __dataclass_transform__ diff --git a/strawberry/federation/schema.py b/strawberry/federation/schema.py index 240442ad0c..0cc90a2289 100644 --- a/strawberry/federation/schema.py +++ b/strawberry/federation/schema.py @@ -4,8 +4,8 @@ from itertools import chain from typing import Any, Dict, Iterable, List, Optional, Type, Union, cast +from graphql import ExecutionContext as GraphQLExecutionContext from graphql import ( - ExecutionContext as GraphQLExecutionContext, GraphQLError, GraphQLField, GraphQLInterfaceType, diff --git a/strawberry/field.py b/strawberry/field.py index d74fb12e32..03000abe75 100644 --- a/strawberry/field.py +++ b/strawberry/field.py @@ -17,7 +17,6 @@ Union, overload, ) - from typing_extensions import Literal from strawberry.annotation import StrawberryAnnotation diff --git a/strawberry/http/__init__.py b/strawberry/http/__init__.py index ed209b6264..20cc55ac19 100644 --- a/strawberry/http/__init__.py +++ b/strawberry/http/__init__.py @@ -1,7 +1,6 @@ import json from dataclasses import dataclass from typing import Any, Dict, List, Mapping, Optional - from typing_extensions import TypedDict from graphql.error.graphql_error import format_error as format_graphql_error diff --git a/strawberry/mutation.py b/strawberry/mutation.py index ff86762feb..3a617c49f0 100644 --- a/strawberry/mutation.py +++ b/strawberry/mutation.py @@ -3,7 +3,7 @@ from .field import field -# Mutations and subscriptions are field, we might want to separate things in the long run -# for example to provide better errors +# Mutations and subscriptions are field, we might want to separate +# things in the long run for example to provide better errors mutation = field subscription = partial(field, is_subscription=True) diff --git a/strawberry/printer/printer.py b/strawberry/printer/printer.py index 39600fa054..0c799ff013 100644 --- a/strawberry/printer/printer.py +++ b/strawberry/printer/printer.py @@ -41,8 +41,8 @@ print_description, print_implemented_interfaces, print_specified_by_url, - print_type as original_print_type, ) +from graphql.utilities.print_schema import print_type as original_print_type from strawberry.custom_scalar import ScalarWrapper from strawberry.enum import EnumDefinition diff --git a/strawberry/private.py b/strawberry/private.py index 5f8412333b..50dd06f282 100644 --- a/strawberry/private.py +++ b/strawberry/private.py @@ -1,5 +1,4 @@ from typing import TypeVar - from typing_extensions import Annotated, get_args, get_origin diff --git a/strawberry/sanic/views.py b/strawberry/sanic/views.py index 4f431e7929..0ea542e90e 100644 --- a/strawberry/sanic/views.py +++ b/strawberry/sanic/views.py @@ -1,6 +1,5 @@ import json from typing import Any, Dict, Optional, Type, Union - from typing_extensions import Literal from sanic.exceptions import SanicException, ServerError diff --git a/strawberry/schema/base.py b/strawberry/schema/base.py index 535804eb5d..3fd40a5717 100644 --- a/strawberry/schema/base.py +++ b/strawberry/schema/base.py @@ -1,7 +1,6 @@ from abc import abstractmethod from functools import lru_cache from typing import Any, Dict, Iterable, List, Optional, Type, Union - from typing_extensions import Protocol from graphql import GraphQLError diff --git a/strawberry/schema/execute.py b/strawberry/schema/execute.py index 14eb1aedab..0064dec692 100644 --- a/strawberry/schema/execute.py +++ b/strawberry/schema/execute.py @@ -13,14 +13,10 @@ cast, ) -from graphql import ( - ExecutionContext as GraphQLExecutionContext, - ExecutionResult as GraphQLExecutionResult, - GraphQLError, - GraphQLSchema, - execute as original_execute, - parse, -) +from graphql import ExecutionContext as GraphQLExecutionContext +from graphql import ExecutionResult as GraphQLExecutionResult +from graphql import GraphQLError, GraphQLSchema, parse +from graphql import execute as original_execute from graphql.language import DocumentNode from graphql.validation import ASTValidationRule, validate diff --git a/strawberry/schema/name_converter.py b/strawberry/schema/name_converter.py index b3bbfc01cb..4c3d39298c 100644 --- a/strawberry/schema/name_converter.py +++ b/strawberry/schema/name_converter.py @@ -1,7 +1,6 @@ from __future__ import annotations from typing import TYPE_CHECKING, List, Optional, Union, cast - from typing_extensions import Protocol from strawberry.annotation import StrawberryAnnotation diff --git a/strawberry/schema/schema.py b/strawberry/schema/schema.py index f405052951..6141427a8e 100644 --- a/strawberry/schema/schema.py +++ b/strawberry/schema/schema.py @@ -1,8 +1,8 @@ from functools import lru_cache from typing import Any, Dict, Iterable, List, Optional, Type, Union, cast +from graphql import ExecutionContext as GraphQLExecutionContext from graphql import ( - ExecutionContext as GraphQLExecutionContext, GraphQLNamedType, GraphQLNonNull, GraphQLSchema, @@ -46,7 +46,8 @@ class Schema(BaseSchema): def __init__( self, - # TODO: can we make sure we only allow to pass something that has been decorated? + # TODO: can we make sure we only allow to pass + # something that has been decorated? query: Type, mutation: Optional[Type] = None, subscription: Optional[Type] = None, diff --git a/strawberry/schema/types/base_scalars.py b/strawberry/schema/types/base_scalars.py index ab78685676..f80b3973bc 100644 --- a/strawberry/schema/types/base_scalars.py +++ b/strawberry/schema/types/base_scalars.py @@ -5,7 +5,6 @@ from typing import Callable import dateutil.parser - from graphql import GraphQLError from strawberry.custom_scalar import scalar diff --git a/strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py b/strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py index f736d03fd5..abbdf13e02 100644 --- a/strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py +++ b/strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py @@ -4,12 +4,8 @@ from datetime import timedelta from typing import Any, AsyncGenerator, Callable, Dict, List, Optional -from graphql import ( - ExecutionResult as GraphQLExecutionResult, - GraphQLError, - GraphQLSyntaxError, - parse, -) +from graphql import ExecutionResult as GraphQLExecutionResult +from graphql import GraphQLError, GraphQLSyntaxError, parse from graphql.error.graphql_error import format_error as format_graphql_error from strawberry.schema import BaseSchema diff --git a/strawberry/subscriptions/protocols/graphql_ws/handlers.py b/strawberry/subscriptions/protocols/graphql_ws/handlers.py index 42f894b1ae..21e5b1e604 100644 --- a/strawberry/subscriptions/protocols/graphql_ws/handlers.py +++ b/strawberry/subscriptions/protocols/graphql_ws/handlers.py @@ -3,7 +3,8 @@ from contextlib import suppress from typing import Any, AsyncGenerator, Dict, Optional, cast -from graphql import ExecutionResult as GraphQLExecutionResult, GraphQLError +from graphql import ExecutionResult as GraphQLExecutionResult +from graphql import GraphQLError from graphql.error.graphql_error import format_error as format_graphql_error from strawberry.schema import BaseSchema diff --git a/strawberry/subscriptions/protocols/graphql_ws/types.py b/strawberry/subscriptions/protocols/graphql_ws/types.py index 9dceb025db..dacca31216 100644 --- a/strawberry/subscriptions/protocols/graphql_ws/types.py +++ b/strawberry/subscriptions/protocols/graphql_ws/types.py @@ -1,5 +1,4 @@ from typing import Any, Dict, List, Optional, Union - from typing_extensions import TypedDict from graphql import GraphQLFormattedError diff --git a/strawberry/test/client.py b/strawberry/test/client.py index ebec8ec5c6..aa1e5677b0 100644 --- a/strawberry/test/client.py +++ b/strawberry/test/client.py @@ -2,7 +2,6 @@ from abc import ABC, abstractmethod from dataclasses import dataclass from typing import Any, Coroutine, Dict, List, Mapping, Optional, Union - from typing_extensions import Literal, TypedDict from graphql import GraphQLFormattedError diff --git a/strawberry/type.py b/strawberry/type.py index 2954a82cc0..6a348a1aec 100644 --- a/strawberry/type.py +++ b/strawberry/type.py @@ -3,7 +3,6 @@ from abc import ABC, abstractmethod from typing import TYPE_CHECKING, List, Mapping, TypeVar, Union - if TYPE_CHECKING: from .types.types import TypeDefinition diff --git a/strawberry/types/execution.py b/strawberry/types/execution.py index a16c7ce3b6..20b59ebe68 100644 --- a/strawberry/types/execution.py +++ b/strawberry/types/execution.py @@ -1,11 +1,8 @@ import dataclasses from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Type -from graphql import ( - ASTValidationRule, - ExecutionResult as GraphQLExecutionResult, - specified_rules, -) +from graphql import ASTValidationRule, specified_rules +from graphql import ExecutionResult as GraphQLExecutionResult from graphql.error.graphql_error import GraphQLError from graphql.language import DocumentNode, OperationDefinitionNode diff --git a/strawberry/types/fields/resolver.py b/strawberry/types/fields/resolver.py index fd0343d0de..4a83a23fda 100644 --- a/strawberry/types/fields/resolver.py +++ b/strawberry/types/fields/resolver.py @@ -22,7 +22,6 @@ _eval_type, cast, ) - from typing_extensions import Annotated, Protocol, get_args, get_origin from strawberry.annotation import StrawberryAnnotation diff --git a/strawberry/types/nodes.py b/strawberry/types/nodes.py index d24b62efcf..e49b5fe1b0 100644 --- a/strawberry/types/nodes.py +++ b/strawberry/types/nodes.py @@ -1,7 +1,8 @@ """ Abstraction layer for graphql-core field nodes. -Call `convert_sections` on a list of GraphQL `FieldNode`s, such as in `info.field_nodes`. +Call `convert_sections` on a list of GraphQL `FieldNode`s, +such as in `info.field_nodes`. If a node has only one useful value, it's value is inlined. @@ -13,18 +14,16 @@ from typing import Any, Collection, Dict, Iterable, List, Optional, Union from graphql import GraphQLResolveInfo -from graphql.language import ( - ArgumentNode as GQLArgumentNode, - DirectiveNode as GQLDirectiveNode, - FieldNode as GQLFieldNode, - FragmentSpreadNode as GQLFragmentSpreadNode, - InlineFragmentNode as GQLInlineFragment, - InlineFragmentNode as GQLInlineFragmentNode, - ListValueNode as GQLListValueNode, - ObjectValueNode as GQLObjectValueNode, - ValueNode as GQLValueNode, - VariableNode as GQLVariableNode, -) +from graphql.language import ArgumentNode as GQLArgumentNode +from graphql.language import DirectiveNode as GQLDirectiveNode +from graphql.language import FieldNode as GQLFieldNode +from graphql.language import FragmentSpreadNode as GQLFragmentSpreadNode +from graphql.language import InlineFragmentNode as GQLInlineFragment +from graphql.language import InlineFragmentNode as GQLInlineFragmentNode +from graphql.language import ListValueNode as GQLListValueNode +from graphql.language import ObjectValueNode as GQLObjectValueNode +from graphql.language import ValueNode as GQLValueNode +from graphql.language import VariableNode as GQLVariableNode Arguments = Dict[str, Any] diff --git a/strawberry/types/types.py b/strawberry/types/types.py index e948ee8865..13177a2e64 100644 --- a/strawberry/types/types.py +++ b/strawberry/types/types.py @@ -13,7 +13,6 @@ TypeVar, Union, ) - from typing_extensions import Self from strawberry.type import StrawberryType, StrawberryTypeVar @@ -50,7 +49,7 @@ def __post_init__(self): # resolve `Self` annotation with the origin type for index, field in enumerate(self.fields): if isinstance(field.type, StrawberryType) and field.type.has_generic(Self): - self.fields[index] = field.copy_with({Self: self.origin}) # type: ignore + self.fields[index] = field.copy_with({Self: self.origin}) # type: ignore # noqa: E501 # TODO: remove wrapped cls when we "merge" this with `StrawberryObject` def resolve_generic(self, wrapped_cls: type) -> type: diff --git a/strawberry/utils/logging.py b/strawberry/utils/logging.py index 172222ac1b..97fdab9418 100644 --- a/strawberry/utils/logging.py +++ b/strawberry/utils/logging.py @@ -1,7 +1,6 @@ import logging import sys from typing import Any, Optional - from typing_extensions import Final from graphql.error import GraphQLError diff --git a/strawberry/utils/typing.py b/strawberry/utils/typing.py index f7c710c1f2..4eb6daa1f8 100644 --- a/strawberry/utils/typing.py +++ b/strawberry/utils/typing.py @@ -1,7 +1,16 @@ import sys from collections.abc import AsyncGenerator -from typing import _GenericAlias # type: ignore -from typing import Any, Callable, ClassVar, Generic, Tuple, Type, TypeVar, Union +from typing import ( # type: ignore + Any, + Callable, + ClassVar, + Generic, + Tuple, + Type, + TypeVar, + Union, + _GenericAlias, +) def is_list(annotation: object) -> bool: diff --git a/tests/aiohttp/app.py b/tests/aiohttp/app.py index 2f89bc6674..d0825cf4e4 100644 --- a/tests/aiohttp/app.py +++ b/tests/aiohttp/app.py @@ -1,7 +1,8 @@ +from tests.aiohttp.schema import Query, schema + from aiohttp import web from strawberry.aiohttp.handlers import GraphQLTransportWSHandler, GraphQLWSHandler from strawberry.aiohttp.views import GraphQLView -from tests.aiohttp.schema import Query, schema class DebuggableGraphQLTransportWSHandler(GraphQLTransportWSHandler): diff --git a/tests/aiohttp/conftest.py b/tests/aiohttp/conftest.py index 3c1f2a414b..39c59af12f 100644 --- a/tests/aiohttp/conftest.py +++ b/tests/aiohttp/conftest.py @@ -1,9 +1,8 @@ import pytest - import pytest_asyncio +from tests.aiohttp.app import create_app from strawberry.aiohttp.test.client import GraphQLTestClient -from tests.aiohttp.app import create_app @pytest_asyncio.fixture diff --git a/tests/aiohttp/test_graphql_transport_ws.py b/tests/aiohttp/test_graphql_transport_ws.py index 5c614daf55..5597480165 100644 --- a/tests/aiohttp/test_graphql_transport_ws.py +++ b/tests/aiohttp/test_graphql_transport_ws.py @@ -3,6 +3,7 @@ from datetime import timedelta import pytest +from tests.aiohttp.app import create_app from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL from strawberry.subscriptions.protocols.graphql_transport_ws.types import ( @@ -16,7 +17,6 @@ SubscribeMessage, SubscribeMessagePayload, ) -from tests.aiohttp.app import create_app async def test_unknown_message_type(aiohttp_client): diff --git a/tests/aiohttp/test_graphql_ws.py b/tests/aiohttp/test_graphql_ws.py index 640e67a683..39ca28df1a 100644 --- a/tests/aiohttp/test_graphql_ws.py +++ b/tests/aiohttp/test_graphql_ws.py @@ -1,5 +1,8 @@ import asyncio +from tests.aiohttp.app import create_app +from tests.aiohttp.schema import schema + from aiohttp import web from strawberry.aiohttp.views import GraphQLView from strawberry.subscriptions import GRAPHQL_WS_PROTOCOL @@ -14,8 +17,6 @@ GQL_START, GQL_STOP, ) -from tests.aiohttp.app import create_app -from tests.aiohttp.schema import schema async def test_simple_subscription(aiohttp_client): diff --git a/tests/asgi/app.py b/tests/asgi/app.py index d46fce82f5..1a53e9bacd 100644 --- a/tests/asgi/app.py +++ b/tests/asgi/app.py @@ -3,10 +3,10 @@ from starlette.requests import Request from starlette.responses import Response from starlette.websockets import WebSocket +from tests.asgi.schema import Query, schema from strawberry.asgi import GraphQL as BaseGraphQL from strawberry.asgi.handlers import GraphQLTransportWSHandler, GraphQLWSHandler -from tests.asgi.schema import Query, schema class DebuggableGraphQLTransportWSHandler(GraphQLTransportWSHandler): diff --git a/tests/asgi/conftest.py b/tests/asgi/conftest.py index de8cd8a279..a534be3531 100644 --- a/tests/asgi/conftest.py +++ b/tests/asgi/conftest.py @@ -1,11 +1,10 @@ import pathlib import pytest - from starlette.testclient import TestClient +from tests.asgi.app import create_app from strawberry.asgi.test import GraphQLTestClient -from tests.asgi.app import create_app @pytest.fixture diff --git a/tests/asgi/test_async.py b/tests/asgi/test_async.py index b35296ff44..e4fdbd366f 100644 --- a/tests/asgi/test_async.py +++ b/tests/asgi/test_async.py @@ -1,7 +1,6 @@ import typing import pytest - from starlette.testclient import TestClient import strawberry diff --git a/tests/asgi/test_graphql_transport_ws.py b/tests/asgi/test_graphql_transport_ws.py index 285f2dfcef..f22cdbafe6 100644 --- a/tests/asgi/test_graphql_transport_ws.py +++ b/tests/asgi/test_graphql_transport_ws.py @@ -4,6 +4,7 @@ from starlette.testclient import TestClient from starlette.websockets import WebSocketDisconnect +from tests.asgi.app import create_app from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL from strawberry.subscriptions.protocols.graphql_transport_ws.types import ( @@ -17,7 +18,6 @@ SubscribeMessage, SubscribeMessagePayload, ) -from tests.asgi.app import create_app def test_unknown_message_type(test_client): diff --git a/tests/asgi/test_graphql_ws.py b/tests/asgi/test_graphql_ws.py index 8f3d9cb6bc..7f85a57ab9 100644 --- a/tests/asgi/test_graphql_ws.py +++ b/tests/asgi/test_graphql_ws.py @@ -1,5 +1,4 @@ import pytest - from starlette.websockets import WebSocketDisconnect from strawberry.subscriptions import GRAPHQL_WS_PROTOCOL diff --git a/tests/asgi/test_http.py b/tests/asgi/test_http.py index cb3c7fc5f3..a187db61b7 100644 --- a/tests/asgi/test_http.py +++ b/tests/asgi/test_http.py @@ -1,5 +1,4 @@ import pytest - from starlette import status diff --git a/tests/asgi/test_view.py b/tests/asgi/test_view.py index eebc3a26dc..ed31f3280d 100644 --- a/tests/asgi/test_view.py +++ b/tests/asgi/test_view.py @@ -1,11 +1,10 @@ import pytest - from starlette import status from starlette.testclient import TestClient from starlette.websockets import WebSocketDisconnect +from tests.asgi.app import create_app from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL -from tests.asgi.app import create_app @pytest.mark.parametrize("path", ("/", "/graphql")) diff --git a/tests/benchmarks/test_execute.py b/tests/benchmarks/test_execute.py index b9cb4bc8d4..386bed25ce 100644 --- a/tests/benchmarks/test_execute.py +++ b/tests/benchmarks/test_execute.py @@ -4,7 +4,6 @@ from typing import List import pytest - from asgiref.sync import async_to_sync import strawberry diff --git a/tests/chalice/test_views.py b/tests/chalice/test_views.py index 5b356d9d41..56a22435e6 100644 --- a/tests/chalice/test_views.py +++ b/tests/chalice/test_views.py @@ -1,7 +1,6 @@ import json import pytest - from werkzeug.urls import url_encode, url_unparse from chalice.test import Client diff --git a/tests/channels/test_graphql_transport_ws.py b/tests/channels/test_graphql_transport_ws.py index aad3d3c289..0e0b7207a8 100644 --- a/tests/channels/test_graphql_transport_ws.py +++ b/tests/channels/test_graphql_transport_ws.py @@ -3,6 +3,7 @@ from datetime import timedelta import pytest +from tests.channels.schema import schema from channels.testing import WebsocketCommunicator from strawberry.channels import GraphQLWSConsumer @@ -18,7 +19,6 @@ SubscribeMessage, SubscribeMessagePayload, ) -from tests.channels.schema import schema pytestmark = [ diff --git a/tests/channels/test_graphql_ws.py b/tests/channels/test_graphql_ws.py index cd70fce3dc..b1b6ae9531 100644 --- a/tests/channels/test_graphql_ws.py +++ b/tests/channels/test_graphql_ws.py @@ -1,4 +1,5 @@ import pytest +from tests.channels.schema import schema from channels.testing import WebsocketCommunicator from strawberry.channels import GraphQLWSConsumer @@ -14,7 +15,6 @@ GQL_START, GQL_STOP, ) -from tests.channels.schema import schema pytestmark = [ diff --git a/tests/channels/test_http_handler.py b/tests/channels/test_http_handler.py index b8e33fb74d..58f90a52f3 100644 --- a/tests/channels/test_http_handler.py +++ b/tests/channels/test_http_handler.py @@ -2,11 +2,11 @@ from typing import Any, Dict, Optional import pytest +from tests.channels.schema import schema from channels.testing import HttpCommunicator from strawberry.channels import GraphQLHTTPConsumer from strawberry.channels.handlers.http_handler import SyncGraphQLHTTPConsumer -from tests.channels.schema import schema def generate_body(query: str, variables: Optional[Dict[str, Any]] = None): diff --git a/tests/channels/test_layers.py b/tests/channels/test_layers.py index 6bdbdd931d..0e9f0e5163 100644 --- a/tests/channels/test_layers.py +++ b/tests/channels/test_layers.py @@ -1,4 +1,5 @@ import pytest +from tests.channels.schema import schema from channels.layers import get_channel_layer from channels.testing import WebsocketCommunicator @@ -13,7 +14,6 @@ SubscribeMessage, SubscribeMessagePayload, ) -from tests.channels.schema import schema @pytest.fixture diff --git a/tests/channels/test_router.py b/tests/channels/test_router.py index be773ecfd4..581f0fe256 100644 --- a/tests/channels/test_router.py +++ b/tests/channels/test_router.py @@ -1,9 +1,9 @@ from unittest import mock import pytest +from tests.channels.schema import schema from strawberry.channels.router import GraphQLProtocolTypeRouter -from tests.channels.schema import schema def _fake_asgi(): diff --git a/tests/channels/test_ws_handler.py b/tests/channels/test_ws_handler.py index 84656a7f30..4efb3cfd56 100644 --- a/tests/channels/test_ws_handler.py +++ b/tests/channels/test_ws_handler.py @@ -1,4 +1,5 @@ import pytest +from tests.channels.schema import schema from channels.testing.websocket import WebsocketCommunicator from strawberry.channels.handlers.graphql_transport_ws_handler import ( @@ -7,7 +8,6 @@ from strawberry.channels.handlers.graphql_ws_handler import GraphQLWSHandler from strawberry.channels.handlers.ws_handler import GraphQLWSConsumer from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL -from tests.channels.schema import schema async def test_wrong_protocol(): diff --git a/tests/cli/conftest.py b/tests/cli/conftest.py index c81a96335d..3881c4803e 100644 --- a/tests/cli/conftest.py +++ b/tests/cli/conftest.py @@ -1,7 +1,6 @@ import sys import pytest - from click.testing import CliRunner from starlette.testclient import TestClient diff --git a/tests/cli/test_codegen.py b/tests/cli/test_codegen.py index 4710b163d9..fbcfd38614 100644 --- a/tests/cli/test_codegen.py +++ b/tests/cli/test_codegen.py @@ -3,7 +3,8 @@ import pytest -from strawberry.cli.commands.codegen import ConsolePlugin, codegen as cmd_codegen +from strawberry.cli.commands.codegen import ConsolePlugin +from strawberry.cli.commands.codegen import codegen as cmd_codegen from strawberry.codegen import CodegenFile, CodegenResult, QueryCodegenPlugin from strawberry.codegen.types import GraphQLOperation, GraphQLType diff --git a/tests/cli/test_server.py b/tests/cli/test_server.py index 343c94bdf9..249d0e90f8 100644 --- a/tests/cli/test_server.py +++ b/tests/cli/test_server.py @@ -2,7 +2,6 @@ import sys import pytest - import uvicorn from strawberry.cli.commands.server import server as cmd_server diff --git a/tests/codegen/conftest.py b/tests/codegen/conftest.py index ff1b15ed1b..52732a8cf9 100644 --- a/tests/codegen/conftest.py +++ b/tests/codegen/conftest.py @@ -2,12 +2,11 @@ import decimal import enum from typing import TYPE_CHECKING, List, NewType, Optional +from typing_extensions import Annotated from uuid import UUID import pytest -from typing_extensions import Annotated - import strawberry diff --git a/tests/codegen/test_query_codegen.py b/tests/codegen/test_query_codegen.py index 7a1c678b98..e6ccb0e7c5 100644 --- a/tests/codegen/test_query_codegen.py +++ b/tests/codegen/test_query_codegen.py @@ -1,15 +1,14 @@ # # TODO: -# # 2. test fragments -# # 3. test variables -# # 7. test input objects -# # 13. test mutations (raise?) -# # 14. test subscriptions (raise) +# - 1. test fragments +# - 2. test variables +# - 3. test input objects +# - 4. test mutations (raise?) +# - 5. test subscriptions (raise) from pathlib import Path from typing import Type import pytest - from pytest_snapshot.plugin import Snapshot from strawberry.codegen import QueryCodegen, QueryCodegenPlugin diff --git a/tests/django/conftest.py b/tests/django/conftest.py index 874021454c..0c0266b7f3 100644 --- a/tests/django/conftest.py +++ b/tests/django/conftest.py @@ -1,7 +1,6 @@ import pathlib import pytest - from django.test.client import Client from strawberry.django.test import GraphQLTestClient diff --git a/tests/django/test_async_view.py b/tests/django/test_async_view.py index 6dd036f50d..930dd0a021 100644 --- a/tests/django/test_async_view.py +++ b/tests/django/test_async_view.py @@ -1,10 +1,8 @@ import json +import django import pytest - from asgiref.sync import sync_to_async - -import django from django.core.exceptions import BadRequest, SuspiciousOperation from django.test.client import RequestFactory from django.utils.http import urlencode diff --git a/tests/django/test_dataloaders.py b/tests/django/test_dataloaders.py index 8d9e74ebf1..2f331e09de 100644 --- a/tests/django/test_dataloaders.py +++ b/tests/django/test_dataloaders.py @@ -1,11 +1,9 @@ import json from typing import List +import django import pytest - from asgiref.sync import sync_to_async - -import django from django.test.client import RequestFactory import strawberry diff --git a/tests/django/test_views.py b/tests/django/test_views.py index 566a7152e0..edefd388c1 100644 --- a/tests/django/test_views.py +++ b/tests/django/test_views.py @@ -2,14 +2,14 @@ from typing import Any, Optional import pytest - from django.core.exceptions import BadRequest, SuspiciousOperation from django.http import Http404, JsonResponse from django.test.client import RequestFactory from django.utils.http import urlencode import strawberry -from strawberry.django.views import GraphQLView as BaseGraphQLView, TemporalHttpResponse +from strawberry.django.views import GraphQLView as BaseGraphQLView +from strawberry.django.views import TemporalHttpResponse from strawberry.permission import BasePermission from strawberry.types import ExecutionResult, Info diff --git a/tests/experimental/pydantic/test_basic.py b/tests/experimental/pydantic/test_basic.py index 4ed46c7dfd..dd82464631 100644 --- a/tests/experimental/pydantic/test_basic.py +++ b/tests/experimental/pydantic/test_basic.py @@ -2,9 +2,8 @@ from enum import Enum from typing import Any, List, Optional, Union -import pytest - import pydantic +import pytest import strawberry from strawberry.enum import EnumDefinition diff --git a/tests/experimental/pydantic/test_conversion.py b/tests/experimental/pydantic/test_conversion.py index d0c5392dad..488335295b 100644 --- a/tests/experimental/pydantic/test_conversion.py +++ b/tests/experimental/pydantic/test_conversion.py @@ -6,7 +6,6 @@ from typing import Any, Dict, List, NewType, Optional, Union, cast import pytest - from pydantic import BaseConfig, BaseModel, Field, ValidationError from pydantic.fields import ModelField from pydantic.typing import NoArgAnyCallable diff --git a/tests/experimental/pydantic/test_error_type.py b/tests/experimental/pydantic/test_error_type.py index f850f93ec3..72dcfd3203 100644 --- a/tests/experimental/pydantic/test_error_type.py +++ b/tests/experimental/pydantic/test_error_type.py @@ -1,8 +1,7 @@ from typing import List, Optional -import pytest - import pydantic +import pytest import strawberry from strawberry.experimental.pydantic.exceptions import MissingFieldsListError diff --git a/tests/experimental/pydantic/test_fields.py b/tests/experimental/pydantic/test_fields.py index 66e67b9485..59ba76897b 100644 --- a/tests/experimental/pydantic/test_fields.py +++ b/tests/experimental/pydantic/test_fields.py @@ -1,11 +1,10 @@ import re from typing import List - -import pytest +from typing_extensions import Literal import pydantic +import pytest from pydantic import BaseModel, ValidationError, conlist -from typing_extensions import Literal import strawberry from strawberry.type import StrawberryOptional diff --git a/tests/fastapi/app.py b/tests/fastapi/app.py index 99768b03c9..67e4d7897b 100644 --- a/tests/fastapi/app.py +++ b/tests/fastapi/app.py @@ -1,7 +1,8 @@ +from tests.fastapi.schema import schema + from fastapi import BackgroundTasks, Depends, FastAPI, Request, WebSocket from strawberry.fastapi import GraphQLRouter as BaseGraphQLRouter from strawberry.fastapi.handlers import GraphQLTransportWSHandler, GraphQLWSHandler -from tests.fastapi.schema import schema class DebuggableGraphQLTransportWSHandler(GraphQLTransportWSHandler): diff --git a/tests/fastapi/conftest.py b/tests/fastapi/conftest.py index 27f65b0df9..3cb6830b56 100644 --- a/tests/fastapi/conftest.py +++ b/tests/fastapi/conftest.py @@ -1,7 +1,7 @@ import pytest +from tests.fastapi.app import create_app from fastapi.testclient import TestClient -from tests.fastapi.app import create_app @pytest.fixture diff --git a/tests/fastapi/test_async.py b/tests/fastapi/test_async.py index 3985536c3c..3d725e1801 100644 --- a/tests/fastapi/test_async.py +++ b/tests/fastapi/test_async.py @@ -1,11 +1,10 @@ import typing import pytest - from starlette.testclient import TestClient +from tests.fastapi.app import create_app import strawberry -from tests.fastapi.app import create_app @pytest.fixture diff --git a/tests/fastapi/test_context.py b/tests/fastapi/test_context.py index 25205f67fe..1d7b101d6b 100644 --- a/tests/fastapi/test_context.py +++ b/tests/fastapi/test_context.py @@ -1,7 +1,6 @@ from typing import Dict import pytest - from starlette.testclient import TestClient import strawberry diff --git a/tests/fastapi/test_graphql_transport_ws.py b/tests/fastapi/test_graphql_transport_ws.py index 55cfb4ce6f..e8383c09da 100644 --- a/tests/fastapi/test_graphql_transport_ws.py +++ b/tests/fastapi/test_graphql_transport_ws.py @@ -4,6 +4,7 @@ from starlette.testclient import TestClient from starlette.websockets import WebSocketDisconnect +from tests.fastapi.app import create_app from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL from strawberry.subscriptions.protocols.graphql_transport_ws.types import ( @@ -17,7 +18,6 @@ SubscribeMessage, SubscribeMessagePayload, ) -from tests.fastapi.app import create_app def test_unknown_message_type(test_client): diff --git a/tests/fastapi/test_graphql_ws.py b/tests/fastapi/test_graphql_ws.py index 82d92da1de..4c1d90f298 100644 --- a/tests/fastapi/test_graphql_ws.py +++ b/tests/fastapi/test_graphql_ws.py @@ -1,5 +1,4 @@ import pytest - from starlette.websockets import WebSocketDisconnect from strawberry.subscriptions import GRAPHQL_WS_PROTOCOL diff --git a/tests/fastapi/test_query.py b/tests/fastapi/test_query.py index a15f149340..ac6df2ce0f 100644 --- a/tests/fastapi/test_query.py +++ b/tests/fastapi/test_query.py @@ -1,9 +1,10 @@ +from tests.fastapi.app import create_app + import strawberry from fastapi import FastAPI from fastapi.testclient import TestClient from strawberry.fastapi import GraphQLRouter from strawberry.types import ExecutionResult, Info -from tests.fastapi.app import create_app def test_simple_query(test_client): diff --git a/tests/fastapi/test_router.py b/tests/fastapi/test_router.py index 78e1d0856f..787eb0b915 100644 --- a/tests/fastapi/test_router.py +++ b/tests/fastapi/test_router.py @@ -1,5 +1,4 @@ import pytest - from starlette.testclient import TestClient import strawberry diff --git a/tests/fastapi/test_view.py b/tests/fastapi/test_view.py index d2c2e4eaee..7f9c2707b3 100644 --- a/tests/fastapi/test_view.py +++ b/tests/fastapi/test_view.py @@ -1,11 +1,10 @@ import pytest - from starlette import status from starlette.testclient import TestClient from starlette.websockets import WebSocketDisconnect +from tests.fastapi.app import create_app from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL -from tests.fastapi.app import create_app def test_renders_graphiql(test_client): diff --git a/tests/federation/printer/test_inaccessible.py b/tests/federation/printer/test_inaccessible.py index fd956744f9..444b44aa41 100644 --- a/tests/federation/printer/test_inaccessible.py +++ b/tests/federation/printer/test_inaccessible.py @@ -1,7 +1,6 @@ import textwrap from enum import Enum from typing import List - from typing_extensions import Annotated import strawberry diff --git a/tests/federation/printer/test_tag.py b/tests/federation/printer/test_tag.py index 70bf832fb9..c15e127ff2 100644 --- a/tests/federation/printer/test_tag.py +++ b/tests/federation/printer/test_tag.py @@ -1,7 +1,6 @@ import textwrap from enum import Enum from typing import List - from typing_extensions import Annotated import strawberry diff --git a/tests/fields/test_arguments.py b/tests/fields/test_arguments.py index 4cbe3e42ad..ac6a6dd0a0 100644 --- a/tests/fields/test_arguments.py +++ b/tests/fields/test_arguments.py @@ -1,10 +1,9 @@ import sys from typing import List, Optional +from typing_extensions import Annotated import pytest -from typing_extensions import Annotated - import strawberry from strawberry import UNSET from strawberry.exceptions import InvalidFieldArgument, MultipleStrawberryArgumentsError @@ -377,8 +376,8 @@ def test_annotated_with_other_information(): class Query: @strawberry.field def name( - self, argument: Annotated[str, "Some other info"] # noqa: F722 - ) -> str: + self, argument: Annotated[str, "Some other info"] + ) -> str: # noqa: F722 return "Name" definition = Query._type_definition diff --git a/tests/flask/app.py b/tests/flask/app.py index f3d79fe157..4b17f6196d 100644 --- a/tests/flask/app.py +++ b/tests/flask/app.py @@ -3,10 +3,8 @@ import strawberry from flask import Flask from strawberry.file_uploads import Upload -from strawberry.flask.views import ( - AsyncGraphQLView as BaseAsyncGraphQLView, - GraphQLView as BaseGraphQLView, -) +from strawberry.flask.views import AsyncGraphQLView as BaseAsyncGraphQLView +from strawberry.flask.views import GraphQLView as BaseGraphQLView def create_app(use_async_view=False, **kwargs): diff --git a/tests/objects/generics/test_names.py b/tests/objects/generics/test_names.py index 7b1b689730..ffbdc3904a 100644 --- a/tests/objects/generics/test_names.py +++ b/tests/objects/generics/test_names.py @@ -1,10 +1,9 @@ import textwrap from typing import Generic, List, NewType, TypeVar +from typing_extensions import Annotated import pytest -from typing_extensions import Annotated - import strawberry from strawberry.enum import EnumDefinition from strawberry.lazy_type import LazyType diff --git a/tests/pyright/utils.py b/tests/pyright/utils.py index 6df7b9f8a2..5f4e18657c 100644 --- a/tests/pyright/utils.py +++ b/tests/pyright/utils.py @@ -5,11 +5,10 @@ import tempfile from dataclasses import dataclass from typing import List, cast +from typing_extensions import Literal import pytest -from typing_extensions import Literal - ResultType = Literal["error", "information"] diff --git a/tests/schema/extensions/test_apollo.py b/tests/schema/extensions/test_apollo.py index 60cd6c34c0..b13c9dacd9 100644 --- a/tests/schema/extensions/test_apollo.py +++ b/tests/schema/extensions/test_apollo.py @@ -1,7 +1,5 @@ import pytest - from freezegun import freeze_time - from graphql.utilities import get_introspection_query import strawberry diff --git a/tests/schema/extensions/test_extensions.py b/tests/schema/extensions/test_extensions.py index b568eca4a6..c3f8f38c66 100644 --- a/tests/schema/extensions/test_extensions.py +++ b/tests/schema/extensions/test_extensions.py @@ -3,12 +3,9 @@ from unittest.mock import patch import pytest - -from graphql import ( - ExecutionResult as GraphQLExecutionResult, - GraphQLError, - execute as original_execute, -) +from graphql import ExecutionResult as GraphQLExecutionResult +from graphql import GraphQLError +from graphql import execute as original_execute import strawberry from strawberry.extensions import Extension diff --git a/tests/schema/extensions/test_imports.py b/tests/schema/extensions/test_imports.py index f0937a5665..13a41a7fc6 100644 --- a/tests/schema/extensions/test_imports.py +++ b/tests/schema/extensions/test_imports.py @@ -5,30 +5,6 @@ def test_can_import(mocker): # mocking sys.modules.ddtrace so we don't get an ImportError mocker.patch.dict("sys.modules", ddtrace=mocker.MagicMock()) - from strawberry.extensions.tracing import ( # noqa - ApolloTracingExtension, - ApolloTracingExtensionSync, - DatadogTracingExtension, - DatadogTracingExtensionSync, - OpenTelemetryExtension, - OpenTelemetryExtensionSync, - apollo, - datadog, - opentelemetry, - ) - from strawberry.extensions.tracing.apollo import ( # noqa - ApolloTracingExtension, - ApolloTracingExtensionSync, - ) - from strawberry.extensions.tracing.datadog import ( # noqa - DatadogTracingExtension, - DatadogTracingExtensionSync, - ) - from strawberry.extensions.tracing.opentelemetry import ( # noqa - OpenTelemetryExtension, - OpenTelemetryExtensionSync, - ) - def test_fails_if_import_is_not_found(): with pytest.raises(ImportError): diff --git a/tests/schema/extensions/test_opentelemetry.py b/tests/schema/extensions/test_opentelemetry.py index 8a5e34afee..54ae86f423 100644 --- a/tests/schema/extensions/test_opentelemetry.py +++ b/tests/schema/extensions/test_opentelemetry.py @@ -1,5 +1,4 @@ import pytest - from opentelemetry.trace import SpanKind import strawberry diff --git a/tests/schema/extensions/test_parser_cache.py b/tests/schema/extensions/test_parser_cache.py index 5382860880..3d75724a0f 100644 --- a/tests/schema/extensions/test_parser_cache.py +++ b/tests/schema/extensions/test_parser_cache.py @@ -1,7 +1,6 @@ from unittest.mock import patch import pytest - from graphql import parse import strawberry diff --git a/tests/schema/extensions/test_query_depth_limiter.py b/tests/schema/extensions/test_query_depth_limiter.py index 412d4b44ff..bd0e0ac458 100644 --- a/tests/schema/extensions/test_query_depth_limiter.py +++ b/tests/schema/extensions/test_query_depth_limiter.py @@ -2,7 +2,6 @@ from typing import List, Optional import pytest - from graphql import get_introspection_query, parse, specified_rules, validate import strawberry diff --git a/tests/schema/extensions/test_validation_cache.py b/tests/schema/extensions/test_validation_cache.py index c396835acd..00bf7c644d 100644 --- a/tests/schema/extensions/test_validation_cache.py +++ b/tests/schema/extensions/test_validation_cache.py @@ -1,7 +1,6 @@ from unittest.mock import patch import pytest - from graphql import validate import strawberry diff --git a/tests/schema/test_arguments.py b/tests/schema/test_arguments.py index 83ded7f23c..0d4f7ee583 100644 --- a/tests/schema/test_arguments.py +++ b/tests/schema/test_arguments.py @@ -1,6 +1,5 @@ from textwrap import dedent from typing import Optional - from typing_extensions import Annotated import strawberry diff --git a/tests/schema/test_enum.py b/tests/schema/test_enum.py index a915ac0eb2..244d8f212a 100644 --- a/tests/schema/test_enum.py +++ b/tests/schema/test_enum.py @@ -2,11 +2,10 @@ from enum import Enum from textwrap import dedent from typing import List, Optional +from typing_extensions import Annotated import pytest -from typing_extensions import Annotated - import strawberry from strawberry.lazy_type import lazy diff --git a/tests/schema/test_execution.py b/tests/schema/test_execution.py index 3a169ca784..12ac9e528b 100644 --- a/tests/schema/test_execution.py +++ b/tests/schema/test_execution.py @@ -4,7 +4,6 @@ from unittest.mock import patch import pytest - from graphql import GraphQLError, ValidationRule, validate import strawberry diff --git a/tests/schema/test_generics.py b/tests/schema/test_generics.py index 8665cb4d33..62243424a0 100644 --- a/tests/schema/test_generics.py +++ b/tests/schema/test_generics.py @@ -1,11 +1,10 @@ import textwrap from enum import Enum from typing import Any, Generic, List, Optional, TypeVar, Union +from typing_extensions import Self import pytest -from typing_extensions import Self - import strawberry diff --git a/tests/schema/test_lazy/test_lazy_generic.py b/tests/schema/test_lazy/test_lazy_generic.py index 44c6d5a14e..b7eab6f64f 100644 --- a/tests/schema/test_lazy/test_lazy_generic.py +++ b/tests/schema/test_lazy/test_lazy_generic.py @@ -1,5 +1,4 @@ from typing import TYPE_CHECKING, Generic, TypeVar - from typing_extensions import Annotated import strawberry diff --git a/tests/schema/test_lazy/type_a.py b/tests/schema/test_lazy/type_a.py index d62ab0e86b..0f9fcff65c 100644 --- a/tests/schema/test_lazy/type_a.py +++ b/tests/schema/test_lazy/type_a.py @@ -1,5 +1,4 @@ from typing import TYPE_CHECKING, List, Optional - from typing_extensions import Annotated import strawberry diff --git a/tests/schema/test_lazy/type_b.py b/tests/schema/test_lazy/type_b.py index 01c2545f28..501d521eae 100644 --- a/tests/schema/test_lazy/type_b.py +++ b/tests/schema/test_lazy/type_b.py @@ -1,5 +1,4 @@ from typing import TYPE_CHECKING - from typing_extensions import Annotated import strawberry diff --git a/tests/schema/test_schema_generation.py b/tests/schema/test_schema_generation.py index 80e380be8d..5770eb7349 100644 --- a/tests/schema/test_schema_generation.py +++ b/tests/schema/test_schema_generation.py @@ -1,9 +1,8 @@ from typing import Any, Dict, List, Optional import pytest - +from graphql import ExecutionContext as GraphQLExecutionContext from graphql import ( - ExecutionContext as GraphQLExecutionContext, ExecutionResult, GraphQLError, GraphQLField, @@ -11,8 +10,8 @@ GraphQLObjectType, GraphQLSchema, GraphQLString, - print_schema as graphql_core_print_schema, ) +from graphql import print_schema as graphql_core_print_schema import strawberry diff --git a/tests/schema/test_union.py b/tests/schema/test_union.py index d98ab2592a..088a9dd463 100644 --- a/tests/schema/test_union.py +++ b/tests/schema/test_union.py @@ -2,11 +2,10 @@ from dataclasses import dataclass from textwrap import dedent from typing import Generic, List, Optional, TypeVar, Union +from typing_extensions import Annotated import pytest -from typing_extensions import Annotated - import strawberry from strawberry.lazy_type import lazy diff --git a/tests/schema/types/test_date.py b/tests/schema/types/test_date.py index fa695b2764..6ae3fbd8ed 100644 --- a/tests/schema/types/test_date.py +++ b/tests/schema/types/test_date.py @@ -1,7 +1,6 @@ import datetime import pytest - from graphql import GraphQLError import strawberry diff --git a/tests/schema/types/test_datetime.py b/tests/schema/types/test_datetime.py index 7b08ccad8a..19e1ed4dcd 100644 --- a/tests/schema/types/test_datetime.py +++ b/tests/schema/types/test_datetime.py @@ -1,9 +1,7 @@ import datetime -import pytest - import dateutil.tz - +import pytest from graphql import GraphQLError import strawberry diff --git a/tests/schema/types/test_time.py b/tests/schema/types/test_time.py index 057ce4b248..f8d0f5c090 100644 --- a/tests/schema/types/test_time.py +++ b/tests/schema/types/test_time.py @@ -1,7 +1,6 @@ import datetime import pytest - from graphql import GraphQLError import strawberry diff --git a/tests/test_auto.py b/tests/test_auto.py index 47b6dbb78b..09d8fa9786 100644 --- a/tests/test_auto.py +++ b/tests/test_auto.py @@ -1,5 +1,4 @@ from typing import Any, cast - from typing_extensions import Annotated, get_args import strawberry diff --git a/tests/test_printer/test_basic.py b/tests/test_printer/test_basic.py index fe822dc23f..76da620198 100644 --- a/tests/test_printer/test_basic.py +++ b/tests/test_printer/test_basic.py @@ -141,7 +141,7 @@ class MyInput: id_number: strawberry.ID = strawberry.ID(123) # type: ignore id_number_string: strawberry.ID = strawberry.ID("123") x: Optional[int] = UNSET - l: List[str] = strawberry.field(default_factory=list) + l: List[str] = strawberry.field(default_factory=list) # noqa: E741 list_with_values: List[str] = strawberry.field( default_factory=lambda: ["a", "b"] ) diff --git a/tests/test_printer/test_schema_directives.py b/tests/test_printer/test_schema_directives.py index 337fb55ac8..672836ce9c 100644 --- a/tests/test_printer/test_schema_directives.py +++ b/tests/test_printer/test_schema_directives.py @@ -1,7 +1,6 @@ import textwrap from enum import Enum from typing import List, Optional - from typing_extensions import Annotated import strawberry diff --git a/tests/types/resolving/test_parse_annotated.py b/tests/types/resolving/test_parse_annotated.py index 7853997421..16ff8d5c99 100644 --- a/tests/types/resolving/test_parse_annotated.py +++ b/tests/types/resolving/test_parse_annotated.py @@ -1,5 +1,4 @@ from typing import List, Optional, Union - from typing_extensions import Annotated from strawberry.annotation import StrawberryAnnotation diff --git a/tests/utils/test_arguments_converter.py b/tests/utils/test_arguments_converter.py index 01ca841cbd..8f1973c65f 100644 --- a/tests/utils/test_arguments_converter.py +++ b/tests/utils/test_arguments_converter.py @@ -1,6 +1,5 @@ from enum import Enum from typing import List, Optional - from typing_extensions import Annotated import strawberry diff --git a/tests/utils/test_importer.py b/tests/utils/test_importer.py index 9754e35168..ac016ba6b4 100644 --- a/tests/utils/test_importer.py +++ b/tests/utils/test_importer.py @@ -1,7 +1,7 @@ import pytest +from tests.fixtures.sample_package.sample_module import sample_instance, schema from strawberry.utils.importer import import_module_symbol -from tests.fixtures.sample_package.sample_module import sample_instance, schema def test_symbol_import():