strawberry-graphql 0.283.0__py3-none-any.whl → 0.284.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of strawberry-graphql might be problematic. Click here for more details.

Files changed (146) hide show
  1. strawberry/aiohttp/test/client.py +8 -15
  2. strawberry/aiohttp/views.py +12 -15
  3. strawberry/annotation.py +19 -23
  4. strawberry/asgi/__init__.py +18 -17
  5. strawberry/asgi/test/client.py +6 -6
  6. strawberry/chalice/views.py +6 -6
  7. strawberry/channels/handlers/base.py +7 -8
  8. strawberry/channels/handlers/http_handler.py +18 -20
  9. strawberry/channels/handlers/ws_handler.py +10 -12
  10. strawberry/channels/router.py +3 -4
  11. strawberry/channels/testing.py +7 -9
  12. strawberry/cli/commands/codegen.py +7 -7
  13. strawberry/cli/commands/schema_codegen.py +1 -2
  14. strawberry/cli/commands/upgrade/__init__.py +1 -3
  15. strawberry/cli/commands/upgrade/_run_codemod.py +2 -2
  16. strawberry/codegen/plugins/print_operation.py +2 -2
  17. strawberry/codegen/plugins/python.py +2 -2
  18. strawberry/codegen/query_codegen.py +20 -30
  19. strawberry/codegen/types.py +32 -32
  20. strawberry/codemods/annotated_unions.py +2 -2
  21. strawberry/dataloader.py +28 -24
  22. strawberry/directive.py +6 -7
  23. strawberry/django/test/client.py +3 -3
  24. strawberry/django/views.py +16 -19
  25. strawberry/exceptions/__init__.py +4 -4
  26. strawberry/exceptions/conflicting_arguments.py +2 -2
  27. strawberry/exceptions/duplicated_type_name.py +4 -4
  28. strawberry/exceptions/exception.py +3 -3
  29. strawberry/exceptions/handler.py +8 -7
  30. strawberry/exceptions/invalid_argument_type.py +2 -2
  31. strawberry/exceptions/invalid_superclass_interface.py +2 -2
  32. strawberry/exceptions/invalid_union_type.py +4 -4
  33. strawberry/exceptions/missing_arguments_annotations.py +2 -2
  34. strawberry/exceptions/missing_dependencies.py +2 -4
  35. strawberry/exceptions/missing_field_annotation.py +2 -2
  36. strawberry/exceptions/missing_return_annotation.py +2 -2
  37. strawberry/exceptions/object_is_not_a_class.py +2 -2
  38. strawberry/exceptions/object_is_not_an_enum.py +2 -2
  39. strawberry/exceptions/permission_fail_silently_requires_optional.py +2 -2
  40. strawberry/exceptions/private_strawberry_field.py +2 -2
  41. strawberry/exceptions/scalar_already_registered.py +2 -2
  42. strawberry/exceptions/syntax.py +3 -3
  43. strawberry/exceptions/unresolved_field_type.py +2 -2
  44. strawberry/exceptions/utils/source_finder.py +25 -25
  45. strawberry/experimental/pydantic/_compat.py +8 -7
  46. strawberry/experimental/pydantic/conversion.py +2 -2
  47. strawberry/experimental/pydantic/conversion_types.py +2 -2
  48. strawberry/experimental/pydantic/error_type.py +10 -12
  49. strawberry/experimental/pydantic/fields.py +9 -15
  50. strawberry/experimental/pydantic/object_type.py +15 -23
  51. strawberry/experimental/pydantic/utils.py +1 -2
  52. strawberry/ext/mypy_plugin.py +12 -14
  53. strawberry/extensions/base_extension.py +2 -1
  54. strawberry/extensions/context.py +13 -18
  55. strawberry/extensions/directives.py +3 -1
  56. strawberry/extensions/field_extension.py +4 -4
  57. strawberry/extensions/max_aliases.py +1 -3
  58. strawberry/extensions/parser_cache.py +1 -2
  59. strawberry/extensions/query_depth_limiter.py +18 -14
  60. strawberry/extensions/runner.py +2 -2
  61. strawberry/extensions/tracing/apollo.py +3 -3
  62. strawberry/extensions/tracing/datadog.py +3 -3
  63. strawberry/extensions/tracing/opentelemetry.py +6 -8
  64. strawberry/extensions/tracing/utils.py +3 -1
  65. strawberry/extensions/utils.py +2 -2
  66. strawberry/extensions/validation_cache.py +1 -2
  67. strawberry/fastapi/context.py +6 -6
  68. strawberry/fastapi/router.py +33 -36
  69. strawberry/federation/argument.py +4 -5
  70. strawberry/federation/enum.py +18 -21
  71. strawberry/federation/field.py +94 -97
  72. strawberry/federation/object_type.py +56 -58
  73. strawberry/federation/scalar.py +27 -35
  74. strawberry/federation/schema.py +15 -16
  75. strawberry/federation/schema_directive.py +7 -6
  76. strawberry/federation/schema_directives.py +11 -11
  77. strawberry/federation/union.py +4 -4
  78. strawberry/flask/views.py +10 -11
  79. strawberry/http/__init__.py +14 -14
  80. strawberry/http/async_base_view.py +23 -28
  81. strawberry/http/base.py +11 -12
  82. strawberry/http/ides.py +2 -3
  83. strawberry/http/sync_base_view.py +11 -13
  84. strawberry/http/types.py +3 -3
  85. strawberry/litestar/controller.py +40 -35
  86. strawberry/permission.py +4 -6
  87. strawberry/printer/ast_from_value.py +3 -5
  88. strawberry/printer/printer.py +8 -13
  89. strawberry/quart/views.py +12 -14
  90. strawberry/relay/exceptions.py +4 -4
  91. strawberry/relay/fields.py +33 -32
  92. strawberry/relay/types.py +31 -34
  93. strawberry/relay/utils.py +2 -2
  94. strawberry/resolvers.py +2 -1
  95. strawberry/sanic/context.py +1 -0
  96. strawberry/sanic/utils.py +3 -3
  97. strawberry/sanic/views.py +11 -14
  98. strawberry/scalars.py +2 -2
  99. strawberry/schema/_graphql_core.py +5 -5
  100. strawberry/schema/base.py +32 -33
  101. strawberry/schema/compat.py +9 -9
  102. strawberry/schema/config.py +5 -2
  103. strawberry/schema/exceptions.py +1 -3
  104. strawberry/schema/name_converter.py +6 -6
  105. strawberry/schema/schema.py +55 -60
  106. strawberry/schema/schema_converter.py +27 -22
  107. strawberry/schema/types/base_scalars.py +1 -1
  108. strawberry/schema/types/concrete_type.py +5 -5
  109. strawberry/schema_codegen/__init__.py +3 -3
  110. strawberry/schema_directive.py +7 -6
  111. strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py +5 -6
  112. strawberry/subscriptions/protocols/graphql_transport_ws/types.py +20 -20
  113. strawberry/subscriptions/protocols/graphql_ws/handlers.py +5 -6
  114. strawberry/subscriptions/protocols/graphql_ws/types.py +14 -14
  115. strawberry/test/client.py +18 -18
  116. strawberry/tools/create_type.py +2 -3
  117. strawberry/types/arguments.py +25 -26
  118. strawberry/types/auto.py +3 -4
  119. strawberry/types/base.py +25 -27
  120. strawberry/types/enum.py +22 -25
  121. strawberry/types/execution.py +14 -15
  122. strawberry/types/field.py +108 -108
  123. strawberry/types/fields/resolver.py +19 -21
  124. strawberry/types/info.py +5 -11
  125. strawberry/types/lazy_type.py +2 -3
  126. strawberry/types/maybe.py +12 -3
  127. strawberry/types/mutation.py +115 -118
  128. strawberry/types/nodes.py +2 -2
  129. strawberry/types/object_type.py +43 -63
  130. strawberry/types/scalar.py +37 -43
  131. strawberry/types/union.py +12 -14
  132. strawberry/utils/aio.py +12 -9
  133. strawberry/utils/await_maybe.py +3 -3
  134. strawberry/utils/deprecations.py +2 -2
  135. strawberry/utils/importer.py +1 -2
  136. strawberry/utils/inspect.py +4 -6
  137. strawberry/utils/logging.py +2 -2
  138. strawberry/utils/operation.py +4 -4
  139. strawberry/utils/typing.py +18 -83
  140. {strawberry_graphql-0.283.0.dist-info → strawberry_graphql-0.284.3.dist-info}/METADATA +2 -2
  141. strawberry_graphql-0.284.3.dist-info/RECORD +243 -0
  142. strawberry/utils/dataclasses.py +0 -37
  143. strawberry_graphql-0.283.0.dist-info/RECORD +0 -244
  144. {strawberry_graphql-0.283.0.dist-info → strawberry_graphql-0.284.3.dist-info}/WHEEL +0 -0
  145. {strawberry_graphql-0.283.0.dist-info → strawberry_graphql-0.284.3.dist-info}/entry_points.txt +0 -0
  146. {strawberry_graphql-0.283.0.dist-info → strawberry_graphql-0.284.3.dist-info}/licenses/LICENSE +0 -0
strawberry/dataloader.py CHANGED
@@ -8,11 +8,8 @@ from dataclasses import dataclass
8
8
  from typing import (
9
9
  TYPE_CHECKING,
10
10
  Any,
11
- Callable,
12
11
  Generic,
13
- Optional,
14
12
  TypeVar,
15
- Union,
16
13
  overload,
17
14
  )
18
15
 
@@ -20,7 +17,14 @@ from .exceptions import WrongNumberOfResultsReturned
20
17
 
21
18
  if TYPE_CHECKING:
22
19
  from asyncio.events import AbstractEventLoop
23
- from collections.abc import Awaitable, Hashable, Iterable, Mapping, Sequence
20
+ from collections.abc import (
21
+ Awaitable,
22
+ Callable,
23
+ Hashable,
24
+ Iterable,
25
+ Mapping,
26
+ Sequence,
27
+ )
24
28
 
25
29
 
26
30
  T = TypeVar("T")
@@ -46,9 +50,9 @@ class Batch(Generic[K, T]):
46
50
  return len(self.tasks)
47
51
 
48
52
 
49
- class AbstractCache(Generic[K, T], ABC):
53
+ class AbstractCache(ABC, Generic[K, T]):
50
54
  @abstractmethod
51
- def get(self, key: K) -> Union[Future[T], None]:
55
+ def get(self, key: K) -> Future[T] | None:
52
56
  pass
53
57
 
54
58
  @abstractmethod
@@ -65,13 +69,13 @@ class AbstractCache(Generic[K, T], ABC):
65
69
 
66
70
 
67
71
  class DefaultCache(AbstractCache[K, T]):
68
- def __init__(self, cache_key_fn: Optional[Callable[[K], Hashable]] = None) -> None:
72
+ def __init__(self, cache_key_fn: Callable[[K], Hashable] | None = None) -> None:
69
73
  self.cache_key_fn: Callable[[K], Hashable] = (
70
74
  cache_key_fn if cache_key_fn is not None else lambda x: x
71
75
  )
72
76
  self.cache_map: dict[Hashable, Future[T]] = {}
73
77
 
74
- def get(self, key: K) -> Union[Future[T], None]:
78
+ def get(self, key: K) -> Future[T] | None:
75
79
  return self.cache_map.get(self.cache_key_fn(key))
76
80
 
77
81
  def set(self, key: K, value: Future[T]) -> None:
@@ -85,7 +89,7 @@ class DefaultCache(AbstractCache[K, T]):
85
89
 
86
90
 
87
91
  class DataLoader(Generic[K, T]):
88
- batch: Optional[Batch[K, T]] = None
92
+ batch: Batch[K, T] | None = None
89
93
  cache: bool = False
90
94
  cache_map: AbstractCache[K, T]
91
95
 
@@ -93,12 +97,12 @@ class DataLoader(Generic[K, T]):
93
97
  def __init__(
94
98
  self,
95
99
  # any BaseException is rethrown in 'load', so should be excluded from the T type
96
- load_fn: Callable[[list[K]], Awaitable[Sequence[Union[T, BaseException]]]],
97
- max_batch_size: Optional[int] = None,
100
+ load_fn: Callable[[list[K]], Awaitable[Sequence[T | BaseException]]],
101
+ max_batch_size: int | None = None,
98
102
  cache: bool = True,
99
- loop: Optional[AbstractEventLoop] = None,
100
- cache_map: Optional[AbstractCache[K, T]] = None,
101
- cache_key_fn: Optional[Callable[[K], Hashable]] = None,
103
+ loop: AbstractEventLoop | None = None,
104
+ cache_map: AbstractCache[K, T] | None = None,
105
+ cache_key_fn: Callable[[K], Hashable] | None = None,
102
106
  ) -> None: ...
103
107
 
104
108
  # fallback if load_fn is untyped and there's no other info for inference
@@ -106,21 +110,21 @@ class DataLoader(Generic[K, T]):
106
110
  def __init__(
107
111
  self: DataLoader[K, Any],
108
112
  load_fn: Callable[[list[K]], Awaitable[list[Any]]],
109
- max_batch_size: Optional[int] = None,
113
+ max_batch_size: int | None = None,
110
114
  cache: bool = True,
111
- loop: Optional[AbstractEventLoop] = None,
112
- cache_map: Optional[AbstractCache[K, T]] = None,
113
- cache_key_fn: Optional[Callable[[K], Hashable]] = None,
115
+ loop: AbstractEventLoop | None = None,
116
+ cache_map: AbstractCache[K, T] | None = None,
117
+ cache_key_fn: Callable[[K], Hashable] | None = None,
114
118
  ) -> None: ...
115
119
 
116
120
  def __init__(
117
121
  self,
118
- load_fn: Callable[[list[K]], Awaitable[Sequence[Union[T, BaseException]]]],
119
- max_batch_size: Optional[int] = None,
122
+ load_fn: Callable[[list[K]], Awaitable[Sequence[T | BaseException]]],
123
+ max_batch_size: int | None = None,
120
124
  cache: bool = True,
121
- loop: Optional[AbstractEventLoop] = None,
122
- cache_map: Optional[AbstractCache[K, T]] = None,
123
- cache_key_fn: Optional[Callable[[K], Hashable]] = None,
125
+ loop: AbstractEventLoop | None = None,
126
+ cache_map: AbstractCache[K, T] | None = None,
127
+ cache_key_fn: Callable[[K], Hashable] | None = None,
124
128
  ):
125
129
  self.load_fn = load_fn
126
130
  self.max_batch_size = max_batch_size
@@ -244,7 +248,7 @@ async def dispatch_batch(loader: DataLoader, batch: Batch) -> None:
244
248
  expected=len(batch), received=len(values)
245
249
  )
246
250
 
247
- for task, value in zip(batch.tasks, values):
251
+ for task, value in zip(batch.tasks, values, strict=True):
248
252
  # Trying to set_result in a cancelled future would raise
249
253
  # asyncio.exceptions.InvalidStateError
250
254
  if task.future.cancelled():
strawberry/directive.py CHANGED
@@ -6,9 +6,7 @@ from typing import (
6
6
  TYPE_CHECKING,
7
7
  Annotated,
8
8
  Any,
9
- Callable,
10
9
  Generic,
11
- Optional,
12
10
  TypeVar,
13
11
  )
14
12
 
@@ -24,6 +22,7 @@ from strawberry.types.unset import UNSET
24
22
 
25
23
  if TYPE_CHECKING:
26
24
  import inspect
25
+ from collections.abc import Callable
27
26
 
28
27
  from strawberry.types.arguments import StrawberryArgument
29
28
 
@@ -82,17 +81,17 @@ class StrawberryDirectiveResolver(StrawberryResolver[T]):
82
81
  )
83
82
 
84
83
  @cached_property
85
- def value_parameter(self) -> Optional[inspect.Parameter]:
84
+ def value_parameter(self) -> inspect.Parameter | None:
86
85
  return self.reserved_parameters.get(VALUE_PARAMSPEC)
87
86
 
88
87
 
89
88
  @dataclasses.dataclass
90
89
  class StrawberryDirective(Generic[T]):
91
90
  python_name: str
92
- graphql_name: Optional[str]
91
+ graphql_name: str | None
93
92
  resolver: StrawberryDirectiveResolver[T]
94
93
  locations: list[DirectiveLocation]
95
- description: Optional[str] = None
94
+ description: str | None = None
96
95
 
97
96
  @cached_property
98
97
  def arguments(self) -> list[StrawberryArgument]:
@@ -102,8 +101,8 @@ class StrawberryDirective(Generic[T]):
102
101
  def directive(
103
102
  *,
104
103
  locations: list[DirectiveLocation],
105
- description: Optional[str] = None,
106
- name: Optional[str] = None,
104
+ description: str | None = None,
105
+ name: str | None = None,
107
106
  ) -> Callable[[Callable[..., T]], StrawberryDirective[T]]:
108
107
  """Decorator to create a GraphQL operation directive.
109
108
 
@@ -1,4 +1,4 @@
1
- from typing import Any, Optional
1
+ from typing import Any
2
2
 
3
3
  from strawberry.test import BaseGraphQLTestClient
4
4
 
@@ -7,8 +7,8 @@ class GraphQLTestClient(BaseGraphQLTestClient):
7
7
  def request(
8
8
  self,
9
9
  body: dict[str, object],
10
- headers: Optional[dict[str, object]] = None,
11
- files: Optional[dict[str, object]] = None,
10
+ headers: dict[str, object] | None = None,
11
+ files: dict[str, object] | None = None,
12
12
  ) -> Any:
13
13
  if files:
14
14
  return self._client.post(
@@ -5,11 +5,8 @@ import warnings
5
5
  from typing import (
6
6
  TYPE_CHECKING,
7
7
  Any,
8
- Callable,
9
- Optional,
10
- Union,
8
+ TypeGuard,
11
9
  )
12
- from typing_extensions import TypeGuard
13
10
 
14
11
  from asgiref.sync import markcoroutinefunction
15
12
  from django.core.serializers.json import DjangoJSONEncoder
@@ -37,7 +34,7 @@ from strawberry.http.typevars import (
37
34
  from .context import StrawberryDjangoContext
38
35
 
39
36
  if TYPE_CHECKING:
40
- from collections.abc import AsyncIterator
37
+ from collections.abc import AsyncIterator, Callable
41
38
 
42
39
  from django.template.response import TemplateResponse
43
40
 
@@ -48,7 +45,7 @@ if TYPE_CHECKING:
48
45
 
49
46
  # TODO: remove this and unify temporal responses
50
47
  class TemporalHttpResponse(JsonResponse):
51
- status_code: Optional[int] = None # pyright: ignore
48
+ status_code: int | None = None # pyright: ignore
52
49
 
53
50
  def __init__(self) -> None:
54
51
  super().__init__({})
@@ -71,8 +68,8 @@ class BaseView:
71
68
  def __init__(
72
69
  self,
73
70
  schema: BaseSchema,
74
- graphiql: Optional[str] = None,
75
- graphql_ide: Optional[GraphQL_IDE] = "graphiql",
71
+ graphiql: str | None = None,
72
+ graphql_ide: GraphQL_IDE | None = "graphiql",
76
73
  allow_queries_via_get: bool = True,
77
74
  multipart_uploads_enabled: bool = False,
78
75
  **kwargs: Any,
@@ -95,7 +92,7 @@ class BaseView:
95
92
 
96
93
  def create_response(
97
94
  self,
98
- response_data: Union[GraphQLHTTPResponse, list[GraphQLHTTPResponse]],
95
+ response_data: GraphQLHTTPResponse | list[GraphQLHTTPResponse],
99
96
  sub_response: HttpResponse,
100
97
  ) -> HttpResponseBase:
101
98
  data = self.encode_json(response_data)
@@ -143,13 +140,13 @@ class GraphQLView(
143
140
  ],
144
141
  View,
145
142
  ):
146
- graphiql: Optional[bool] = None
147
- graphql_ide: Optional[GraphQL_IDE] = "graphiql"
143
+ graphiql: bool | None = None
144
+ graphql_ide: GraphQL_IDE | None = "graphiql"
148
145
  allow_queries_via_get = True
149
146
  schema: BaseSchema = None # type: ignore
150
147
  request_adapter_class = DjangoHTTPRequestAdapter
151
148
 
152
- def get_root_value(self, request: HttpRequest) -> Optional[RootValue]:
149
+ def get_root_value(self, request: HttpRequest) -> RootValue | None:
153
150
  return None
154
151
 
155
152
  def get_context(self, request: HttpRequest, response: HttpResponse) -> Context:
@@ -160,7 +157,7 @@ class GraphQLView(
160
157
 
161
158
  def dispatch(
162
159
  self, request: HttpRequest, *args: Any, **kwargs: Any
163
- ) -> Union[HttpResponseNotAllowed, TemplateResponse, HttpResponseBase]:
160
+ ) -> HttpResponseNotAllowed | TemplateResponse | HttpResponseBase:
164
161
  try:
165
162
  return self.run(request=request)
166
163
  except HTTPException as e:
@@ -191,8 +188,8 @@ class AsyncGraphQLView(
191
188
  ],
192
189
  View,
193
190
  ):
194
- graphiql: Optional[bool] = None
195
- graphql_ide: Optional[GraphQL_IDE] = "graphiql"
191
+ graphiql: bool | None = None
192
+ graphql_ide: GraphQL_IDE | None = "graphiql"
196
193
  allow_queries_via_get = True
197
194
  schema: BaseSchema = None # type: ignore
198
195
  request_adapter_class = AsyncDjangoHTTPRequestAdapter
@@ -207,7 +204,7 @@ class AsyncGraphQLView(
207
204
 
208
205
  return view
209
206
 
210
- async def get_root_value(self, request: HttpRequest) -> Optional[RootValue]:
207
+ async def get_root_value(self, request: HttpRequest) -> RootValue | None:
211
208
  return None
212
209
 
213
210
  async def get_context(
@@ -220,7 +217,7 @@ class AsyncGraphQLView(
220
217
 
221
218
  async def dispatch( # pyright: ignore
222
219
  self, request: HttpRequest, *args: Any, **kwargs: Any
223
- ) -> Union[HttpResponseNotAllowed, TemplateResponse, HttpResponseBase]:
220
+ ) -> HttpResponseNotAllowed | TemplateResponse | HttpResponseBase:
224
221
  try:
225
222
  return await self.run(request=request)
226
223
  except HTTPException as e:
@@ -240,11 +237,11 @@ class AsyncGraphQLView(
240
237
  def is_websocket_request(self, request: HttpRequest) -> TypeGuard[HttpRequest]:
241
238
  return False
242
239
 
243
- async def pick_websocket_subprotocol(self, request: HttpRequest) -> Optional[str]:
240
+ async def pick_websocket_subprotocol(self, request: HttpRequest) -> str | None:
244
241
  raise NotImplementedError
245
242
 
246
243
  async def create_websocket_response(
247
- self, request: HttpRequest, subprotocol: Optional[str]
244
+ self, request: HttpRequest, subprotocol: str | None
248
245
  ) -> TemporalHttpResponse:
249
246
  raise NotImplementedError
250
247
 
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from functools import cached_property
4
- from typing import TYPE_CHECKING, Optional, Union
4
+ from typing import TYPE_CHECKING
5
5
 
6
6
  from graphql import GraphQLError
7
7
 
@@ -72,20 +72,20 @@ class InvalidTypeInputForUnion(Exception):
72
72
  class MissingTypesForGenericError(Exception):
73
73
  """Raised when a generic types was used without passing any type."""
74
74
 
75
- def __init__(self, annotation: Union[StrawberryType, type]) -> None:
75
+ def __init__(self, annotation: StrawberryType | type) -> None:
76
76
  message = f'The type "{annotation!r}" is generic, but no type has been passed'
77
77
 
78
78
  super().__init__(message)
79
79
 
80
80
 
81
81
  class UnsupportedTypeError(StrawberryException):
82
- def __init__(self, annotation: Union[StrawberryType, type]) -> None:
82
+ def __init__(self, annotation: StrawberryType | type) -> None:
83
83
  message = f"{annotation} conversion is not supported"
84
84
 
85
85
  super().__init__(message)
86
86
 
87
87
  @cached_property
88
- def exception_source(self) -> Optional[ExceptionSource]:
88
+ def exception_source(self) -> ExceptionSource | None:
89
89
  return None
90
90
 
91
91
 
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from functools import cached_property
4
- from typing import TYPE_CHECKING, Optional
4
+ from typing import TYPE_CHECKING
5
5
 
6
6
  from .exception import StrawberryException
7
7
  from .utils.source_finder import SourceFinder
@@ -43,7 +43,7 @@ class ConflictingArgumentsError(StrawberryException):
43
43
  )
44
44
 
45
45
  @cached_property
46
- def exception_source(self) -> Optional[ExceptionSource]:
46
+ def exception_source(self) -> ExceptionSource | None:
47
47
  if self.function is None:
48
48
  return None # pragma: no cover
49
49
 
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from functools import cached_property
4
- from typing import TYPE_CHECKING, Optional
4
+ from typing import TYPE_CHECKING
5
5
 
6
6
  from .exception import StrawberryException
7
7
  from .utils.source_finder import SourceFinder
@@ -17,8 +17,8 @@ class DuplicatedTypeName(StrawberryException):
17
17
 
18
18
  def __init__(
19
19
  self,
20
- first_cls: Optional[type],
21
- second_cls: Optional[type],
20
+ first_cls: type | None,
21
+ second_cls: type | None,
22
22
  duplicated_type_name: str,
23
23
  ) -> None:
24
24
  self.first_cls = first_cls
@@ -66,7 +66,7 @@ class DuplicatedTypeName(StrawberryException):
66
66
  )
67
67
 
68
68
  @cached_property
69
- def exception_source(self) -> Optional[ExceptionSource]:
69
+ def exception_source(self) -> ExceptionSource | None:
70
70
  if self.first_cls is None:
71
71
  return None # pragma: no cover
72
72
 
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  from abc import ABC, abstractmethod
4
4
  from functools import cached_property
5
- from typing import TYPE_CHECKING, Optional
5
+ from typing import TYPE_CHECKING
6
6
 
7
7
  from strawberry.utils.str_converters import to_kebab_case
8
8
 
@@ -40,7 +40,7 @@ class StrawberryException(Exception, ABC):
40
40
 
41
41
  @cached_property
42
42
  @abstractmethod
43
- def exception_source(self) -> Optional[ExceptionSource]:
43
+ def exception_source(self) -> ExceptionSource | None:
44
44
  return None
45
45
 
46
46
  @property
@@ -61,7 +61,7 @@ class StrawberryException(Exception, ABC):
61
61
  f"[link={self.documentation_url}]{self.documentation_url}"
62
62
  ).strip()
63
63
 
64
- def __rich__(self) -> Optional[RenderableType]:
64
+ def __rich__(self) -> RenderableType | None:
65
65
  from rich.box import SIMPLE
66
66
  from rich.console import Group
67
67
  from rich.panel import Panel
@@ -1,8 +1,9 @@
1
1
  import os
2
2
  import sys
3
3
  import threading
4
+ from collections.abc import Callable
4
5
  from types import TracebackType
5
- from typing import Any, Callable, Optional, cast
6
+ from typing import Any, cast
6
7
 
7
8
  from .exception import StrawberryException, UnableToFindExceptionSource
8
9
 
@@ -10,7 +11,7 @@ original_threading_exception_hook = threading.excepthook
10
11
 
11
12
 
12
13
  ExceptionHandler = Callable[
13
- [type[BaseException], BaseException, Optional[TracebackType]], None
14
+ [type[BaseException], BaseException, TracebackType | None], None
14
15
  ]
15
16
 
16
17
 
@@ -31,7 +32,7 @@ def _get_handler(exception_type: type[BaseException]) -> ExceptionHandler:
31
32
  def _handler(
32
33
  exception_type: type[BaseException],
33
34
  exception: BaseException,
34
- traceback: Optional[TracebackType],
35
+ traceback: TracebackType | None,
35
36
  ) -> None:
36
37
  try:
37
38
  rich.print(exception)
@@ -49,7 +50,7 @@ def _get_handler(exception_type: type[BaseException]) -> ExceptionHandler:
49
50
  def strawberry_exception_handler(
50
51
  exception_type: type[BaseException],
51
52
  exception: BaseException,
52
- traceback: Optional[TracebackType],
53
+ traceback: TracebackType | None,
53
54
  ) -> None:
54
55
  _get_handler(exception_type)(exception_type, exception, traceback)
55
56
 
@@ -57,9 +58,9 @@ def strawberry_exception_handler(
57
58
  def strawberry_threading_exception_handler(
58
59
  args: tuple[
59
60
  type[BaseException],
60
- Optional[BaseException],
61
- Optional[TracebackType],
62
- Optional[threading.Thread],
61
+ BaseException | None,
62
+ TracebackType | None,
63
+ threading.Thread | None,
63
64
  ],
64
65
  ) -> None:
65
66
  (exception_type, exception, traceback, _) = args
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from functools import cached_property
4
- from typing import TYPE_CHECKING, Optional
4
+ from typing import TYPE_CHECKING
5
5
 
6
6
  from strawberry.types.base import get_object_definition
7
7
 
@@ -55,7 +55,7 @@ class InvalidArgumentTypeError(StrawberryException):
55
55
  )
56
56
 
57
57
  @cached_property
58
- def exception_source(self) -> Optional[ExceptionSource]:
58
+ def exception_source(self) -> ExceptionSource | None:
59
59
  if self.function is None:
60
60
  return None # pragma: no cover
61
61
 
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from functools import cached_property
4
- from typing import TYPE_CHECKING, Optional
4
+ from typing import TYPE_CHECKING
5
5
 
6
6
  from .exception import StrawberryException
7
7
  from .utils.source_finder import SourceFinder
@@ -36,6 +36,6 @@ class InvalidSuperclassInterfaceError(StrawberryException):
36
36
  super().__init__(self.message)
37
37
 
38
38
  @cached_property
39
- def exception_source(self) -> Optional[ExceptionSource]:
39
+ def exception_source(self) -> ExceptionSource | None:
40
40
  source_finder = SourceFinder()
41
41
  return source_finder.find_class_from_object(self.cls)
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  from functools import cached_property
4
4
  from inspect import getframeinfo, stack
5
5
  from pathlib import Path
6
- from typing import TYPE_CHECKING, Optional
6
+ from typing import TYPE_CHECKING
7
7
 
8
8
  from strawberry.exceptions.utils.source_finder import SourceFinder
9
9
 
@@ -24,7 +24,7 @@ class InvalidUnionTypeError(StrawberryException):
24
24
  self,
25
25
  union_name: str,
26
26
  invalid_type: object,
27
- union_definition: Optional[StrawberryUnion] = None,
27
+ union_definition: StrawberryUnion | None = None,
28
28
  ) -> None:
29
29
  from strawberry.types.base import StrawberryList
30
30
  from strawberry.types.scalar import ScalarWrapper
@@ -58,7 +58,7 @@ class InvalidUnionTypeError(StrawberryException):
58
58
  self.annotation_message = "invalid type here"
59
59
 
60
60
  @cached_property
61
- def exception_source(self) -> Optional[ExceptionSource]:
61
+ def exception_source(self) -> ExceptionSource | None:
62
62
  source_finder = SourceFinder()
63
63
 
64
64
  if self.union_definition:
@@ -100,7 +100,7 @@ class InvalidTypeForUnionMergeError(StrawberryException):
100
100
  self.annotation_message = "invalid type here"
101
101
 
102
102
  @cached_property
103
- def exception_source(self) -> Optional[ExceptionSource]:
103
+ def exception_source(self) -> ExceptionSource | None:
104
104
  source_finder = SourceFinder()
105
105
 
106
106
  return source_finder.find_union_merge(self.union, self.other, frame=self.frame)
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from functools import cached_property
4
- from typing import TYPE_CHECKING, Optional
4
+ from typing import TYPE_CHECKING
5
5
 
6
6
  from .exception import StrawberryException
7
7
  from .utils.source_finder import SourceFinder
@@ -52,7 +52,7 @@ class MissingArgumentsAnnotationsError(StrawberryException):
52
52
  return f'arguments "{head}" and "{arguments[-1]}"'
53
53
 
54
54
  @cached_property
55
- def exception_source(self) -> Optional[ExceptionSource]:
55
+ def exception_source(self) -> ExceptionSource | None:
56
56
  if self.function is None:
57
57
  return None # pragma: no cover
58
58
 
@@ -1,7 +1,5 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import Optional
4
-
5
3
 
6
4
  class MissingOptionalDependenciesError(Exception):
7
5
  """Some optional dependencies that are required for a particular task are missing."""
@@ -9,8 +7,8 @@ class MissingOptionalDependenciesError(Exception):
9
7
  def __init__(
10
8
  self,
11
9
  *,
12
- packages: Optional[list[str]] = None,
13
- extras: Optional[list[str]] = None,
10
+ packages: list[str] | None = None,
11
+ extras: list[str] | None = None,
14
12
  ) -> None:
15
13
  """Initialize the error.
16
14
 
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from functools import cached_property
4
- from typing import TYPE_CHECKING, Optional
4
+ from typing import TYPE_CHECKING
5
5
 
6
6
  from .exception import StrawberryException
7
7
  from .utils.source_finder import SourceFinder
@@ -32,7 +32,7 @@ class MissingFieldAnnotationError(StrawberryException):
32
32
  super().__init__(self.message)
33
33
 
34
34
  @cached_property
35
- def exception_source(self) -> Optional[ExceptionSource]:
35
+ def exception_source(self) -> ExceptionSource | None:
36
36
  if self.cls is None:
37
37
  return None # pragma: no cover
38
38
 
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from functools import cached_property
4
- from typing import TYPE_CHECKING, Optional
4
+ from typing import TYPE_CHECKING
5
5
 
6
6
  from .exception import StrawberryException
7
7
  from .utils.source_finder import SourceFinder
@@ -37,7 +37,7 @@ class MissingReturnAnnotationError(StrawberryException):
37
37
  self.annotation_message = "resolver missing annotation"
38
38
 
39
39
  @cached_property
40
- def exception_source(self) -> Optional[ExceptionSource]:
40
+ def exception_source(self) -> ExceptionSource | None:
41
41
  if self.function is None:
42
42
  return None # pragma: no cover
43
43
 
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  from enum import Enum
4
4
  from functools import cached_property
5
- from typing import TYPE_CHECKING, Optional
5
+ from typing import TYPE_CHECKING
6
6
 
7
7
  from .exception import StrawberryException
8
8
  from .utils.source_finder import SourceFinder
@@ -56,7 +56,7 @@ class ObjectIsNotClassError(StrawberryException):
56
56
  return cls(obj, cls.MethodType.TYPE)
57
57
 
58
58
  @cached_property
59
- def exception_source(self) -> Optional[ExceptionSource]:
59
+ def exception_source(self) -> ExceptionSource | None:
60
60
  if self.function is None:
61
61
  return None # pragma: no cover
62
62
 
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from functools import cached_property
4
- from typing import TYPE_CHECKING, Optional
4
+ from typing import TYPE_CHECKING
5
5
 
6
6
  from .exception import StrawberryException
7
7
  from .utils.source_finder import SourceFinder
@@ -31,7 +31,7 @@ class ObjectIsNotAnEnumError(StrawberryException):
31
31
  super().__init__(self.message)
32
32
 
33
33
  @cached_property
34
- def exception_source(self) -> Optional[ExceptionSource]:
34
+ def exception_source(self) -> ExceptionSource | None:
35
35
  if self.cls is None:
36
36
  return None # pragma: no cover
37
37
 
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from functools import cached_property
4
- from typing import TYPE_CHECKING, Optional
4
+ from typing import TYPE_CHECKING
5
5
 
6
6
  from .exception import StrawberryException
7
7
  from .utils.source_finder import SourceFinder
@@ -32,7 +32,7 @@ class PermissionFailSilentlyRequiresOptionalError(StrawberryException):
32
32
  super().__init__(self.message)
33
33
 
34
34
  @cached_property
35
- def exception_source(self) -> Optional[ExceptionSource]:
35
+ def exception_source(self) -> ExceptionSource | None:
36
36
  origin = self.field.origin
37
37
  source_finder = SourceFinder()
38
38