strawberry-graphql 0.255.0__py3-none-any.whl → 0.256.0__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.
Files changed (155) hide show
  1. strawberry/__init__.py +9 -9
  2. strawberry/aiohttp/test/client.py +10 -8
  3. strawberry/aiohttp/views.py +5 -7
  4. strawberry/annotation.py +12 -15
  5. strawberry/asgi/__init__.py +3 -6
  6. strawberry/asgi/test/client.py +9 -8
  7. strawberry/chalice/views.py +4 -2
  8. strawberry/channels/__init__.py +1 -1
  9. strawberry/channels/handlers/base.py +3 -7
  10. strawberry/channels/handlers/http_handler.py +5 -6
  11. strawberry/channels/handlers/ws_handler.py +3 -4
  12. strawberry/channels/testing.py +5 -9
  13. strawberry/cli/commands/codegen.py +9 -9
  14. strawberry/cli/commands/upgrade/__init__.py +2 -3
  15. strawberry/cli/commands/upgrade/_run_codemod.py +7 -5
  16. strawberry/codegen/exceptions.py +2 -2
  17. strawberry/codegen/plugins/print_operation.py +6 -6
  18. strawberry/codegen/plugins/python.py +6 -6
  19. strawberry/codegen/plugins/typescript.py +3 -3
  20. strawberry/codegen/query_codegen.py +29 -34
  21. strawberry/codegen/types.py +35 -34
  22. strawberry/codemods/annotated_unions.py +5 -2
  23. strawberry/dataloader.py +13 -20
  24. strawberry/directive.py +12 -5
  25. strawberry/django/test/client.py +4 -4
  26. strawberry/django/views.py +4 -5
  27. strawberry/exceptions/__init__.py +24 -24
  28. strawberry/exceptions/conflicting_arguments.py +2 -2
  29. strawberry/exceptions/duplicated_type_name.py +3 -3
  30. strawberry/exceptions/handler.py +7 -7
  31. strawberry/exceptions/invalid_union_type.py +2 -2
  32. strawberry/exceptions/missing_arguments_annotations.py +2 -2
  33. strawberry/exceptions/missing_field_annotation.py +2 -2
  34. strawberry/exceptions/object_is_not_an_enum.py +2 -2
  35. strawberry/exceptions/private_strawberry_field.py +2 -2
  36. strawberry/exceptions/syntax.py +4 -4
  37. strawberry/exceptions/utils/source_finder.py +7 -6
  38. strawberry/experimental/pydantic/__init__.py +3 -3
  39. strawberry/experimental/pydantic/_compat.py +14 -14
  40. strawberry/experimental/pydantic/conversion.py +2 -2
  41. strawberry/experimental/pydantic/conversion_types.py +3 -3
  42. strawberry/experimental/pydantic/error_type.py +18 -16
  43. strawberry/experimental/pydantic/exceptions.py +5 -5
  44. strawberry/experimental/pydantic/fields.py +2 -13
  45. strawberry/experimental/pydantic/object_type.py +20 -22
  46. strawberry/experimental/pydantic/utils.py +6 -10
  47. strawberry/ext/dataclasses/dataclasses.py +3 -3
  48. strawberry/ext/mypy_plugin.py +6 -9
  49. strawberry/extensions/__init__.py +7 -8
  50. strawberry/extensions/add_validation_rules.py +5 -3
  51. strawberry/extensions/base_extension.py +4 -4
  52. strawberry/extensions/context.py +15 -14
  53. strawberry/extensions/directives.py +2 -2
  54. strawberry/extensions/disable_validation.py +1 -1
  55. strawberry/extensions/field_extension.py +2 -1
  56. strawberry/extensions/mask_errors.py +3 -2
  57. strawberry/extensions/max_aliases.py +2 -2
  58. strawberry/extensions/max_tokens.py +1 -1
  59. strawberry/extensions/parser_cache.py +2 -1
  60. strawberry/extensions/pyinstrument.py +4 -1
  61. strawberry/extensions/query_depth_limiter.py +13 -13
  62. strawberry/extensions/runner.py +7 -7
  63. strawberry/extensions/tracing/apollo.py +11 -9
  64. strawberry/extensions/tracing/datadog.py +3 -1
  65. strawberry/extensions/tracing/opentelemetry.py +7 -10
  66. strawberry/extensions/utils.py +3 -3
  67. strawberry/extensions/validation_cache.py +2 -1
  68. strawberry/fastapi/context.py +3 -3
  69. strawberry/fastapi/router.py +9 -14
  70. strawberry/federation/__init__.py +4 -4
  71. strawberry/federation/argument.py +2 -1
  72. strawberry/federation/enum.py +8 -8
  73. strawberry/federation/field.py +25 -28
  74. strawberry/federation/object_type.py +24 -26
  75. strawberry/federation/scalar.py +7 -8
  76. strawberry/federation/schema.py +30 -36
  77. strawberry/federation/schema_directive.py +5 -5
  78. strawberry/federation/schema_directives.py +14 -14
  79. strawberry/federation/union.py +3 -2
  80. strawberry/field_extensions/input_mutation.py +1 -2
  81. strawberry/file_uploads/utils.py +4 -3
  82. strawberry/flask/views.py +3 -2
  83. strawberry/http/__init__.py +6 -6
  84. strawberry/http/async_base_view.py +9 -14
  85. strawberry/http/base.py +5 -4
  86. strawberry/http/ides.py +1 -1
  87. strawberry/http/parse_content_type.py +1 -2
  88. strawberry/http/sync_base_view.py +3 -5
  89. strawberry/http/temporal_response.py +1 -2
  90. strawberry/http/types.py +3 -2
  91. strawberry/litestar/controller.py +8 -14
  92. strawberry/parent.py +1 -2
  93. strawberry/permission.py +6 -8
  94. strawberry/printer/ast_from_value.py +2 -1
  95. strawberry/printer/printer.py +50 -30
  96. strawberry/quart/views.py +3 -3
  97. strawberry/relay/exceptions.py +4 -4
  98. strawberry/relay/fields.py +22 -24
  99. strawberry/relay/types.py +29 -27
  100. strawberry/relay/utils.py +4 -4
  101. strawberry/sanic/utils.py +4 -4
  102. strawberry/sanic/views.py +5 -7
  103. strawberry/scalars.py +2 -2
  104. strawberry/schema/base.py +16 -11
  105. strawberry/schema/compat.py +4 -4
  106. strawberry/schema/execute.py +6 -10
  107. strawberry/schema/name_converter.py +3 -3
  108. strawberry/schema/schema.py +37 -25
  109. strawberry/schema/schema_converter.py +22 -24
  110. strawberry/schema/subscribe.py +4 -3
  111. strawberry/schema/types/base_scalars.py +1 -1
  112. strawberry/schema/types/concrete_type.py +2 -2
  113. strawberry/schema/types/scalar.py +3 -4
  114. strawberry/schema_codegen/__init__.py +4 -4
  115. strawberry/schema_directive.py +8 -8
  116. strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py +8 -9
  117. strawberry/subscriptions/protocols/graphql_transport_ws/types.py +16 -16
  118. strawberry/subscriptions/protocols/graphql_ws/handlers.py +6 -5
  119. strawberry/subscriptions/protocols/graphql_ws/types.py +13 -13
  120. strawberry/test/__init__.py +1 -1
  121. strawberry/test/client.py +21 -19
  122. strawberry/tools/create_type.py +4 -3
  123. strawberry/tools/merge_types.py +1 -2
  124. strawberry/types/__init__.py +1 -1
  125. strawberry/types/arguments.py +10 -12
  126. strawberry/types/auto.py +2 -2
  127. strawberry/types/base.py +17 -21
  128. strawberry/types/enum.py +3 -5
  129. strawberry/types/execution.py +8 -12
  130. strawberry/types/field.py +26 -31
  131. strawberry/types/fields/resolver.py +15 -17
  132. strawberry/types/graphql.py +2 -2
  133. strawberry/types/info.py +5 -9
  134. strawberry/types/lazy_type.py +3 -5
  135. strawberry/types/mutation.py +25 -28
  136. strawberry/types/nodes.py +11 -9
  137. strawberry/types/object_type.py +14 -16
  138. strawberry/types/private.py +1 -2
  139. strawberry/types/scalar.py +2 -2
  140. strawberry/types/type_resolver.py +5 -5
  141. strawberry/types/union.py +8 -11
  142. strawberry/types/unset.py +3 -3
  143. strawberry/utils/aio.py +3 -8
  144. strawberry/utils/await_maybe.py +3 -2
  145. strawberry/utils/debug.py +2 -2
  146. strawberry/utils/deprecations.py +2 -2
  147. strawberry/utils/inspect.py +3 -5
  148. strawberry/utils/str_converters.py +1 -1
  149. strawberry/utils/typing.py +38 -67
  150. {strawberry_graphql-0.255.0.dist-info → strawberry_graphql-0.256.0.dist-info}/METADATA +3 -6
  151. strawberry_graphql-0.256.0.dist-info/RECORD +236 -0
  152. strawberry_graphql-0.255.0.dist-info/RECORD +0 -236
  153. {strawberry_graphql-0.255.0.dist-info → strawberry_graphql-0.256.0.dist-info}/LICENSE +0 -0
  154. {strawberry_graphql-0.255.0.dist-info → strawberry_graphql-0.256.0.dist-info}/WHEEL +0 -0
  155. {strawberry_graphql-0.255.0.dist-info → strawberry_graphql-0.256.0.dist-info}/entry_points.txt +0 -0
@@ -5,10 +5,7 @@ import warnings
5
5
  from typing import (
6
6
  TYPE_CHECKING,
7
7
  Any,
8
- AsyncIterator,
9
8
  Callable,
10
- Dict,
11
- Mapping,
12
9
  Optional,
13
10
  Union,
14
11
  cast,
@@ -42,6 +39,8 @@ from strawberry.http.typevars import (
42
39
  from .context import StrawberryDjangoContext
43
40
 
44
41
  if TYPE_CHECKING:
42
+ from collections.abc import AsyncIterator, Mapping
43
+
45
44
  from django.template.response import TemplateResponse
46
45
 
47
46
  from strawberry.http import GraphQLHTTPResponse
@@ -190,7 +189,7 @@ class BaseView:
190
189
  request: HttpRequest,
191
190
  stream: Callable[[], AsyncIterator[Any]],
192
191
  sub_response: TemporalHttpResponse,
193
- headers: Dict[str, str],
192
+ headers: dict[str, str],
194
193
  ) -> HttpResponseBase:
195
194
  return StreamingHttpResponse(
196
195
  streaming_content=stream(),
@@ -318,4 +317,4 @@ class AsyncGraphQLView(
318
317
  raise NotImplementedError
319
318
 
320
319
 
321
- __all__ = ["GraphQLView", "AsyncGraphQLView"]
320
+ __all__ = ["AsyncGraphQLView", "GraphQLView"]
@@ -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, Dict, Optional, Set, Union
4
+ from typing import TYPE_CHECKING, Optional, Union
5
5
 
6
6
  from graphql import GraphQLError
7
7
 
@@ -48,7 +48,7 @@ class UnallowedReturnTypeForUnion(Exception):
48
48
  """The return type is not in the list of Union types."""
49
49
 
50
50
  def __init__(
51
- self, field_name: str, result_type: str, allowed_types: Set[GraphQLObjectType]
51
+ self, field_name: str, result_type: str, allowed_types: set[GraphQLObjectType]
52
52
  ) -> None:
53
53
  formatted_allowed_types = list(sorted(type_.name for type_ in allowed_types))
54
54
 
@@ -160,37 +160,37 @@ class StrawberryGraphQLError(GraphQLError):
160
160
  class ConnectionRejectionError(Exception):
161
161
  """Use it when you want to reject a WebSocket connection."""
162
162
 
163
- def __init__(self, payload: Dict[str, object] = {}) -> None:
163
+ def __init__(self, payload: dict[str, object] = {}) -> None:
164
164
  self.payload = payload
165
165
 
166
166
 
167
167
  __all__ = [
168
- "StrawberryException",
169
- "UnableToFindExceptionSource",
168
+ "ConflictingArgumentsError",
169
+ "DuplicatedTypeName",
170
+ "FieldWithResolverAndDefaultFactoryError",
171
+ "FieldWithResolverAndDefaultValueError",
172
+ "InvalidArgumentTypeError",
173
+ "InvalidCustomContext",
174
+ "InvalidDefaultFactoryError",
175
+ "InvalidTypeForUnionMergeError",
176
+ "InvalidUnionTypeError",
170
177
  "MissingArgumentsAnnotationsError",
178
+ "MissingFieldAnnotationError",
179
+ "MissingOptionalDependenciesError",
180
+ "MissingQueryError",
171
181
  "MissingReturnAnnotationError",
172
- "WrongReturnTypeForUnion",
173
- "UnallowedReturnTypeForUnion",
182
+ "MissingTypesForGenericError",
183
+ "MultipleStrawberryArgumentsError",
174
184
  "ObjectIsNotAnEnumError",
175
185
  "ObjectIsNotClassError",
176
- "InvalidUnionTypeError",
177
- "InvalidTypeForUnionMergeError",
178
- "MissingTypesForGenericError",
179
- "UnsupportedTypeError",
180
- "UnresolvedFieldTypeError",
181
186
  "PrivateStrawberryFieldError",
182
- "MultipleStrawberryArgumentsError",
183
187
  "ScalarAlreadyRegisteredError",
184
- "WrongNumberOfResultsReturned",
185
- "FieldWithResolverAndDefaultValueError",
186
- "FieldWithResolverAndDefaultFactoryError",
187
- "ConflictingArgumentsError",
188
- "MissingQueryError",
189
- "InvalidArgumentTypeError",
190
- "InvalidDefaultFactoryError",
191
- "InvalidCustomContext",
192
- "MissingFieldAnnotationError",
193
- "DuplicatedTypeName",
188
+ "StrawberryException",
194
189
  "StrawberryGraphQLError",
195
- "MissingOptionalDependenciesError",
190
+ "UnableToFindExceptionSource",
191
+ "UnallowedReturnTypeForUnion",
192
+ "UnresolvedFieldTypeError",
193
+ "UnsupportedTypeError",
194
+ "WrongNumberOfResultsReturned",
195
+ "WrongReturnTypeForUnion",
196
196
  ]
@@ -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, List, Optional
4
+ from typing import TYPE_CHECKING, Optional
5
5
 
6
6
  from .exception import StrawberryException
7
7
  from .utils.source_finder import SourceFinder
@@ -16,7 +16,7 @@ class ConflictingArgumentsError(StrawberryException):
16
16
  def __init__(
17
17
  self,
18
18
  resolver: StrawberryResolver,
19
- arguments: List[str],
19
+ arguments: list[str],
20
20
  ) -> None:
21
21
  self.function = resolver.wrapped_func
22
22
  self.argument_names = arguments
@@ -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, Type
4
+ from typing import TYPE_CHECKING, Optional
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: Optional[type],
21
+ second_cls: Optional[type],
22
22
  duplicated_type_name: str,
23
23
  ) -> None:
24
24
  self.first_cls = first_cls
@@ -2,7 +2,7 @@ import os
2
2
  import sys
3
3
  import threading
4
4
  from types import TracebackType
5
- from typing import Any, Callable, Optional, Tuple, Type, cast
5
+ from typing import Any, Callable, Optional, cast
6
6
 
7
7
  from .exception import StrawberryException, UnableToFindExceptionSource
8
8
 
@@ -10,7 +10,7 @@ original_threading_exception_hook = threading.excepthook
10
10
 
11
11
 
12
12
  ExceptionHandler = Callable[
13
- [Type[BaseException], BaseException, Optional[TracebackType]], None
13
+ [type[BaseException], BaseException, Optional[TracebackType]], None
14
14
  ]
15
15
 
16
16
 
@@ -20,7 +20,7 @@ def should_use_rich_exceptions() -> bool:
20
20
  return errors_disabled.lower() not in ["true", "1", "yes"]
21
21
 
22
22
 
23
- def _get_handler(exception_type: Type[BaseException]) -> ExceptionHandler:
23
+ def _get_handler(exception_type: type[BaseException]) -> ExceptionHandler:
24
24
  if issubclass(exception_type, StrawberryException):
25
25
  try:
26
26
  import rich
@@ -29,7 +29,7 @@ def _get_handler(exception_type: Type[BaseException]) -> ExceptionHandler:
29
29
  else:
30
30
 
31
31
  def _handler(
32
- exception_type: Type[BaseException],
32
+ exception_type: type[BaseException],
33
33
  exception: BaseException,
34
34
  traceback: Optional[TracebackType],
35
35
  ) -> None:
@@ -47,7 +47,7 @@ def _get_handler(exception_type: Type[BaseException]) -> ExceptionHandler:
47
47
 
48
48
 
49
49
  def strawberry_exception_handler(
50
- exception_type: Type[BaseException],
50
+ exception_type: type[BaseException],
51
51
  exception: BaseException,
52
52
  traceback: Optional[TracebackType],
53
53
  ) -> None:
@@ -55,8 +55,8 @@ def strawberry_exception_handler(
55
55
 
56
56
 
57
57
  def strawberry_threading_exception_handler(
58
- args: Tuple[
59
- Type[BaseException],
58
+ args: tuple[
59
+ type[BaseException],
60
60
  Optional[BaseException],
61
61
  Optional[TracebackType],
62
62
  Optional[threading.Thread],
@@ -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, Type
6
+ from typing import TYPE_CHECKING, Optional
7
7
 
8
8
  from strawberry.exceptions.utils.source_finder import SourceFinder
9
9
 
@@ -80,7 +80,7 @@ class InvalidUnionTypeError(StrawberryException):
80
80
  class InvalidTypeForUnionMergeError(StrawberryException):
81
81
  """A specialized version of InvalidUnionTypeError for when trying to merge unions using the pipe operator."""
82
82
 
83
- invalid_type: Type
83
+ invalid_type: type
84
84
 
85
85
  def __init__(self, union: StrawberryUnion, other: object) -> None:
86
86
  self.union = union
@@ -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, List, Optional
4
+ from typing import TYPE_CHECKING, Optional
5
5
 
6
6
  from .exception import StrawberryException
7
7
  from .utils.source_finder import SourceFinder
@@ -18,7 +18,7 @@ class MissingArgumentsAnnotationsError(StrawberryException):
18
18
  def __init__(
19
19
  self,
20
20
  resolver: StrawberryResolver,
21
- arguments: List[str],
21
+ arguments: list[str],
22
22
  ) -> None:
23
23
  self.missing_arguments = arguments
24
24
  self.function = resolver.wrapped_func
@@ -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, Type
4
+ from typing import TYPE_CHECKING, Optional
5
5
 
6
6
  from .exception import StrawberryException
7
7
  from .utils.source_finder import SourceFinder
@@ -11,7 +11,7 @@ if TYPE_CHECKING:
11
11
 
12
12
 
13
13
  class MissingFieldAnnotationError(StrawberryException):
14
- def __init__(self, field_name: str, cls: Type) -> None:
14
+ def __init__(self, field_name: str, cls: type) -> None:
15
15
  self.cls = cls
16
16
  self.field_name = field_name
17
17
 
@@ -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, Type
4
+ from typing import TYPE_CHECKING, Optional
5
5
 
6
6
  from .exception import StrawberryException
7
7
  from .utils.source_finder import SourceFinder
@@ -13,7 +13,7 @@ if TYPE_CHECKING:
13
13
 
14
14
 
15
15
  class ObjectIsNotAnEnumError(StrawberryException):
16
- def __init__(self, cls: Type[Enum]) -> None:
16
+ def __init__(self, cls: type[Enum]) -> None:
17
17
  self.cls = cls
18
18
  self.message = (
19
19
  "strawberry.enum can only be used with subclasses of Enum. "
@@ -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, Type
4
+ from typing import TYPE_CHECKING, Optional
5
5
 
6
6
  from .exception import StrawberryException
7
7
  from .utils.source_finder import SourceFinder
@@ -11,7 +11,7 @@ if TYPE_CHECKING:
11
11
 
12
12
 
13
13
  class PrivateStrawberryFieldError(StrawberryException):
14
- def __init__(self, field_name: str, cls: Type) -> None:
14
+ def __init__(self, field_name: str, cls: type) -> None:
15
15
  self.cls = cls
16
16
  self.field_name = field_name
17
17
 
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import TYPE_CHECKING, Dict, Optional, Set, Tuple
3
+ from typing import TYPE_CHECKING, Optional
4
4
 
5
5
  from pygments.lexers import PythonLexer
6
6
  from rich.segment import Segment
@@ -14,10 +14,10 @@ class Syntax(RichSyntax):
14
14
  def __init__(
15
15
  self,
16
16
  code: str,
17
- line_range: Tuple[int, int],
18
- highlight_lines: Optional[Set[int]] = None,
17
+ line_range: tuple[int, int],
18
+ highlight_lines: Optional[set[int]] = None,
19
19
  line_offset: int = 0,
20
- line_annotations: Optional[Dict[int, str]] = None,
20
+ line_annotations: Optional[dict[int, str]] = None,
21
21
  ) -> None:
22
22
  self.line_offset = line_offset
23
23
  self.line_annotations = line_annotations or {}
@@ -6,11 +6,12 @@ import sys
6
6
  from dataclasses import dataclass
7
7
  from functools import cached_property
8
8
  from pathlib import Path
9
- from typing import TYPE_CHECKING, Any, Callable, Optional, Sequence, Type, cast
9
+ from typing import TYPE_CHECKING, Any, Callable, Optional, cast
10
10
 
11
11
  from ..exception_source import ExceptionSource
12
12
 
13
13
  if TYPE_CHECKING:
14
+ from collections.abc import Sequence
14
15
  from inspect import Traceback
15
16
 
16
17
  from libcst import BinaryOperation, Call, CSTNode, FunctionDef
@@ -113,7 +114,7 @@ class LibCSTSourceFinder:
113
114
  )
114
115
 
115
116
  def _find_class_definition(
116
- self, source: SourcePath, cls: Type[Any]
117
+ self, source: SourcePath, cls: type[Any]
117
118
  ) -> Optional[CSTNode]:
118
119
  import libcst.matchers as m
119
120
 
@@ -122,7 +123,7 @@ class LibCSTSourceFinder:
122
123
  class_defs = self._find(source.code, matcher)
123
124
  return self._find_definition_by_qualname(cls.__qualname__, class_defs)
124
125
 
125
- def find_class(self, cls: Type[Any]) -> Optional[ExceptionSource]:
126
+ def find_class(self, cls: type[Any]) -> Optional[ExceptionSource]:
126
127
  source = self.find_source(cls.__module__)
127
128
 
128
129
  if source is None:
@@ -147,7 +148,7 @@ class LibCSTSourceFinder:
147
148
  )
148
149
 
149
150
  def find_class_attribute(
150
- self, cls: Type[Any], attribute_name: str
151
+ self, cls: type[Any], attribute_name: str
151
152
  ) -> Optional[ExceptionSource]:
152
153
  source = self.find_source(cls.__module__)
153
154
 
@@ -560,11 +561,11 @@ class SourceFinder:
560
561
  except ImportError:
561
562
  return None # pragma: no cover
562
563
 
563
- def find_class_from_object(self, cls: Type[Any]) -> Optional[ExceptionSource]:
564
+ def find_class_from_object(self, cls: type[Any]) -> Optional[ExceptionSource]:
564
565
  return self.cst.find_class(cls) if self.cst else None
565
566
 
566
567
  def find_class_attribute_from_object(
567
- self, cls: Type[Any], attribute_name: str
568
+ self, cls: type[Any], attribute_name: str
568
569
  ) -> Optional[ExceptionSource]:
569
570
  return self.cst.find_class_attribute(cls, attribute_name) if self.cst else None
570
571
 
@@ -1,11 +1,11 @@
1
1
  from .error_type import error_type
2
2
  from .exceptions import UnregisteredTypeException
3
- from .object_type import input, interface, type
3
+ from .object_type import input, interface, type # noqa: A004
4
4
 
5
5
  __all__ = [
6
- "error_type",
7
6
  "UnregisteredTypeException",
7
+ "error_type",
8
8
  "input",
9
- "type",
10
9
  "interface",
10
+ "type",
11
11
  ]
@@ -2,7 +2,7 @@ import dataclasses
2
2
  from dataclasses import dataclass
3
3
  from decimal import Decimal
4
4
  from functools import cached_property
5
- from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Type
5
+ from typing import TYPE_CHECKING, Any, Callable, Optional
6
6
  from uuid import UUID
7
7
 
8
8
  import pydantic
@@ -98,7 +98,7 @@ ATTR_TO_TYPE_MAP_Pydantic_Core_V2 = {
98
98
  }
99
99
 
100
100
 
101
- def get_fields_map_for_v2() -> Dict[Any, Any]:
101
+ def get_fields_map_for_v2() -> dict[Any, Any]:
102
102
  import pydantic_core
103
103
 
104
104
  fields_map = {
@@ -124,7 +124,7 @@ class PydanticV2Compat:
124
124
 
125
125
  return PydanticUndefined
126
126
 
127
- def get_model_fields(self, model: Type[BaseModel]) -> Dict[str, CompatModelField]:
127
+ def get_model_fields(self, model: type[BaseModel]) -> dict[str, CompatModelField]:
128
128
  field_info: dict[str, FieldInfo] = model.model_fields
129
129
  new_fields = {}
130
130
  # Convert it into CompatModelField
@@ -147,10 +147,10 @@ class PydanticV2Compat:
147
147
  return new_fields
148
148
 
149
149
  @cached_property
150
- def fields_map(self) -> Dict[Any, Any]:
150
+ def fields_map(self) -> dict[Any, Any]:
151
151
  return get_fields_map_for_v2()
152
152
 
153
- def get_basic_type(self, type_: Any) -> Type[Any]:
153
+ def get_basic_type(self, type_: Any) -> type[Any]:
154
154
  if type_ in self.fields_map:
155
155
  type_ = self.fields_map[type_]
156
156
 
@@ -162,7 +162,7 @@ class PydanticV2Compat:
162
162
 
163
163
  return type_
164
164
 
165
- def model_dump(self, model_instance: BaseModel) -> Dict[Any, Any]:
165
+ def model_dump(self, model_instance: BaseModel) -> dict[Any, Any]:
166
166
  return model_instance.model_dump()
167
167
 
168
168
 
@@ -171,7 +171,7 @@ class PydanticV1Compat:
171
171
  def PYDANTIC_MISSING_TYPE(self) -> Any:
172
172
  return dataclasses.MISSING
173
173
 
174
- def get_model_fields(self, model: Type[BaseModel]) -> Dict[str, CompatModelField]:
174
+ def get_model_fields(self, model: type[BaseModel]) -> dict[str, CompatModelField]:
175
175
  new_fields = {}
176
176
  # Convert it into CompatModelField
177
177
  for name, field in model.__fields__.items(): # type: ignore[attr-defined]
@@ -192,7 +192,7 @@ class PydanticV1Compat:
192
192
  return new_fields
193
193
 
194
194
  @cached_property
195
- def fields_map(self) -> Dict[Any, Any]:
195
+ def fields_map(self) -> dict[Any, Any]:
196
196
  if IS_PYDANTIC_V2:
197
197
  return {
198
198
  getattr(pydantic.v1, field_name): type
@@ -206,7 +206,7 @@ class PydanticV1Compat:
206
206
  if hasattr(pydantic, field_name)
207
207
  }
208
208
 
209
- def get_basic_type(self, type_: Any) -> Type[Any]:
209
+ def get_basic_type(self, type_: Any) -> type[Any]:
210
210
  if IS_PYDANTIC_V1:
211
211
  ConstrainedInt = pydantic.ConstrainedInt
212
212
  ConstrainedFloat = pydantic.ConstrainedFloat
@@ -225,7 +225,7 @@ class PydanticV1Compat:
225
225
  if lenient_issubclass(type_, ConstrainedStr):
226
226
  return str
227
227
  if lenient_issubclass(type_, ConstrainedList):
228
- return List[self.get_basic_type(type_.item_type)] # type: ignore
228
+ return list[self.get_basic_type(type_.item_type)] # type: ignore
229
229
 
230
230
  if type_ in self.fields_map:
231
231
  type_ = self.fields_map[type_]
@@ -238,7 +238,7 @@ class PydanticV1Compat:
238
238
 
239
239
  return type_
240
240
 
241
- def model_dump(self, model_instance: BaseModel) -> Dict[Any, Any]:
241
+ def model_dump(self, model_instance: BaseModel) -> dict[Any, Any]:
242
242
  return model_instance.dict()
243
243
 
244
244
 
@@ -250,7 +250,7 @@ class PydanticCompat:
250
250
  self._compat = PydanticV1Compat() # type: ignore[assignment]
251
251
 
252
252
  @classmethod
253
- def from_model(cls, model: Type[BaseModel]) -> "PydanticCompat":
253
+ def from_model(cls, model: type[BaseModel]) -> "PydanticCompat":
254
254
  if hasattr(model, "model_fields"):
255
255
  return cls(is_v2=True)
256
256
 
@@ -283,10 +283,10 @@ else:
283
283
 
284
284
  __all__ = [
285
285
  "PydanticCompat",
286
+ "get_args",
287
+ "get_origin",
286
288
  "is_new_type",
287
289
  "lenient_issubclass",
288
- "get_origin",
289
- "get_args",
290
290
  "new_type_supertype",
291
291
  "smart_deepcopy",
292
292
  ]
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import copy
4
4
  import dataclasses
5
- from typing import TYPE_CHECKING, Any, Type, Union, cast
5
+ from typing import TYPE_CHECKING, Any, Union, cast
6
6
 
7
7
  from strawberry.types.base import (
8
8
  StrawberryList,
@@ -98,7 +98,7 @@ def convert_pydantic_model_to_strawberry_class(
98
98
  return cls(**kwargs)
99
99
 
100
100
 
101
- def convert_strawberry_class_to_pydantic_model(obj: Type) -> Any:
101
+ def convert_strawberry_class_to_pydantic_model(obj: type) -> Any:
102
102
  if hasattr(obj, "to_pydantic"):
103
103
  return obj.to_pydantic()
104
104
  elif dataclasses.is_dataclass(obj):
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import TYPE_CHECKING, Any, Dict, Optional, Type, TypeVar
3
+ from typing import TYPE_CHECKING, Any, Optional, TypeVar
4
4
  from typing_extensions import Protocol
5
5
 
6
6
  from pydantic import BaseModel
@@ -22,7 +22,7 @@ class StrawberryTypeFromPydantic(Protocol[PydanticModel]):
22
22
 
23
23
  @staticmethod
24
24
  def from_pydantic(
25
- instance: PydanticModel, extra: Optional[Dict[str, Any]] = None
25
+ instance: PydanticModel, extra: Optional[dict[str, Any]] = None
26
26
  ) -> StrawberryTypeFromPydantic[PydanticModel]: ...
27
27
 
28
28
  def to_pydantic(self, **kwargs: Any) -> PydanticModel: ...
@@ -31,4 +31,4 @@ class StrawberryTypeFromPydantic(Protocol[PydanticModel]):
31
31
  def __strawberry_definition__(self) -> StrawberryObjectDefinition: ...
32
32
 
33
33
  @property
34
- def _pydantic_type(self) -> Type[PydanticModel]: ...
34
+ def _pydantic_type(self) -> type[PydanticModel]: ...
@@ -3,13 +3,10 @@ from __future__ import annotations
3
3
  import dataclasses
4
4
  import warnings
5
5
  from typing import (
6
+ TYPE_CHECKING,
6
7
  Any,
7
8
  Callable,
8
- List,
9
9
  Optional,
10
- Sequence,
11
- Tuple,
12
- Type,
13
10
  Union,
14
11
  cast,
15
12
  )
@@ -33,14 +30,19 @@ from strawberry.utils.typing import get_list_annotation, is_list
33
30
 
34
31
  from .exceptions import MissingFieldsListError
35
32
 
33
+ if TYPE_CHECKING:
34
+ from collections.abc import Sequence
36
35
 
37
- def get_type_for_field(field: CompatModelField) -> Union[Any, Type[None], Type[List]]:
36
+ from strawberry.types.base import WithStrawberryObjectDefinition
37
+
38
+
39
+ def get_type_for_field(field: CompatModelField) -> Union[type[Union[None, list]], Any]:
38
40
  type_ = field.outer_type_
39
41
  type_ = normalize_type(type_)
40
42
  return field_type_to_type(type_)
41
43
 
42
44
 
43
- def field_type_to_type(type_: Type) -> Union[Any, List[Any], None]:
45
+ def field_type_to_type(type_: type) -> Union[Any, list[Any], None]:
44
46
  error_class: Any = str
45
47
  strawberry_type: Any = error_class
46
48
 
@@ -52,26 +54,26 @@ def field_type_to_type(type_: Type) -> Union[Any, List[Any], None]:
52
54
  elif lenient_issubclass(child_type, BaseModel):
53
55
  strawberry_type = get_strawberry_type_from_model(child_type)
54
56
  else:
55
- strawberry_type = List[error_class]
57
+ strawberry_type = list[error_class]
56
58
 
57
59
  strawberry_type = Optional[strawberry_type]
58
60
  elif lenient_issubclass(type_, BaseModel):
59
61
  strawberry_type = get_strawberry_type_from_model(type_)
60
62
  return Optional[strawberry_type]
61
63
 
62
- return Optional[List[strawberry_type]]
64
+ return Optional[list[strawberry_type]]
63
65
 
64
66
 
65
67
  def error_type(
66
- model: Type[BaseModel],
68
+ model: type[BaseModel],
67
69
  *,
68
- fields: Optional[List[str]] = None,
70
+ fields: Optional[list[str]] = None,
69
71
  name: Optional[str] = None,
70
72
  description: Optional[str] = None,
71
73
  directives: Optional[Sequence[object]] = (),
72
74
  all_fields: bool = False,
73
- ) -> Callable[..., Type]:
74
- def wrap(cls: Type) -> Type:
75
+ ) -> Callable[..., type]:
76
+ def wrap(cls: type) -> type:
75
77
  compat = PydanticCompat.from_model(model)
76
78
  model_fields = compat.get_model_fields(model)
77
79
  fields_set = set(fields) if fields else set()
@@ -103,7 +105,7 @@ def error_type(
103
105
  if not fields_set:
104
106
  raise MissingFieldsListError(cls)
105
107
 
106
- all_model_fields: List[Tuple[str, Any, dataclasses.Field]] = [
108
+ all_model_fields: list[tuple[str, Any, dataclasses.Field]] = [
107
109
  (
108
110
  name,
109
111
  get_type_for_field(field),
@@ -113,8 +115,8 @@ def error_type(
113
115
  if name in fields_set
114
116
  ]
115
117
 
116
- wrapped = _wrap_dataclass(cls)
117
- extra_fields = cast(List[dataclasses.Field], _get_fields(wrapped, {}))
118
+ wrapped: type[WithStrawberryObjectDefinition] = _wrap_dataclass(cls)
119
+ extra_fields = cast(list[dataclasses.Field], _get_fields(wrapped, {}))
118
120
  private_fields = get_private_fields(wrapped)
119
121
 
120
122
  all_model_fields.extend(
@@ -146,7 +148,7 @@ def error_type(
146
148
  )
147
149
 
148
150
  model._strawberry_type = cls # type: ignore[attr-defined]
149
- cls._pydantic_type = model
151
+ cls._pydantic_type = model # type: ignore[attr-defined]
150
152
  return cls
151
153
 
152
154
  return wrap