strawberry-graphql 0.166.0__py3-none-any.whl → 0.167.1__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 (63) hide show
  1. strawberry/aiohttp/test/client.py +10 -2
  2. strawberry/annotation.py +1 -1
  3. strawberry/asgi/handlers/http_handler.py +3 -2
  4. strawberry/asgi/test/client.py +2 -2
  5. strawberry/chalice/views.py +1 -0
  6. strawberry/channels/context.py +1 -1
  7. strawberry/channels/handlers/base.py +1 -1
  8. strawberry/channels/handlers/graphql_transport_ws_handler.py +1 -1
  9. strawberry/channels/handlers/graphql_ws_handler.py +1 -1
  10. strawberry/channels/handlers/http_handler.py +5 -5
  11. strawberry/channels/handlers/ws_handler.py +4 -4
  12. strawberry/channels/testing.py +1 -1
  13. strawberry/cli/__init__.py +1 -1
  14. strawberry/cli/commands/codegen.py +3 -3
  15. strawberry/cli/commands/export_schema.py +1 -1
  16. strawberry/cli/commands/server.py +1 -1
  17. strawberry/custom_scalar.py +1 -1
  18. strawberry/dataloader.py +9 -9
  19. strawberry/django/context.py +2 -2
  20. strawberry/django/test/client.py +2 -2
  21. strawberry/django/views.py +11 -5
  22. strawberry/exceptions/handler.py +5 -5
  23. strawberry/exceptions/missing_arguments_annotations.py +1 -1
  24. strawberry/experimental/pydantic/conversion.py +7 -5
  25. strawberry/experimental/pydantic/error_type.py +16 -4
  26. strawberry/experimental/pydantic/fields.py +1 -1
  27. strawberry/experimental/pydantic/object_type.py +2 -1
  28. strawberry/experimental/pydantic/utils.py +1 -1
  29. strawberry/ext/dataclasses/dataclasses.py +2 -1
  30. strawberry/ext/mypy_plugin.py +5 -3
  31. strawberry/extensions/context.py +3 -3
  32. strawberry/extensions/tracing/apollo.py +7 -7
  33. strawberry/extensions/tracing/datadog.py +6 -6
  34. strawberry/extensions/tracing/opentelemetry.py +9 -7
  35. strawberry/fastapi/router.py +1 -1
  36. strawberry/federation/scalar.py +1 -1
  37. strawberry/federation/schema.py +8 -1
  38. strawberry/federation/schema_directive.py +2 -2
  39. strawberry/printer/printer.py +1 -1
  40. strawberry/sanic/context.py +1 -0
  41. strawberry/sanic/views.py +3 -1
  42. strawberry/schema/base.py +1 -1
  43. strawberry/schema/name_converter.py +1 -1
  44. strawberry/schema/schema.py +27 -11
  45. strawberry/schema/schema_converter.py +1 -1
  46. strawberry/schema_directive.py +2 -2
  47. strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py +2 -2
  48. strawberry/test/client.py +1 -1
  49. strawberry/tools/merge_types.py +3 -1
  50. strawberry/types/fields/resolver.py +1 -1
  51. strawberry/types/info.py +1 -0
  52. strawberry/types/type_resolver.py +1 -1
  53. strawberry/utils/await_maybe.py +3 -3
  54. strawberry/utils/dataclasses.py +1 -1
  55. strawberry/utils/debug.py +1 -1
  56. strawberry/utils/inspect.py +2 -2
  57. strawberry/utils/operation.py +1 -1
  58. strawberry/utils/typing.py +1 -1
  59. {strawberry_graphql-0.166.0.dist-info → strawberry_graphql-0.167.1.dist-info}/METADATA +1 -1
  60. {strawberry_graphql-0.166.0.dist-info → strawberry_graphql-0.167.1.dist-info}/RECORD +63 -63
  61. {strawberry_graphql-0.166.0.dist-info → strawberry_graphql-0.167.1.dist-info}/LICENSE +0 -0
  62. {strawberry_graphql-0.166.0.dist-info → strawberry_graphql-0.167.1.dist-info}/WHEEL +0 -0
  63. {strawberry_graphql-0.166.0.dist-info → strawberry_graphql-0.167.1.dist-info}/entry_points.txt +0 -0
@@ -68,7 +68,7 @@ class ExtensionContextManagerBase:
68
68
  "{self.HOOK_NAME}"
69
69
  )
70
70
  elif is_legacy:
71
- warnings.warn(self.DEPRECATION_MESSAGE, DeprecationWarning)
71
+ warnings.warn(self.DEPRECATION_MESSAGE, DeprecationWarning, stacklevel=3)
72
72
  return self.from_legacy(extension, on_start, on_end)
73
73
 
74
74
  if hook_fn:
@@ -140,7 +140,7 @@ class ExtensionContextManagerBase:
140
140
  hook = iterator()
141
141
  return WrappedHook(extension, hook, False)
142
142
 
143
- def run_hooks_sync(self, is_exit: bool = False):
143
+ def run_hooks_sync(self, is_exit: bool = False) -> None:
144
144
  """Run extensions synchronously."""
145
145
  ctx = (
146
146
  contextlib.suppress(StopIteration, StopAsyncIteration)
@@ -157,7 +157,7 @@ class ExtensionContextManagerBase:
157
157
  else:
158
158
  hook.initialized_hook.__next__() # type: ignore[union-attr]
159
159
 
160
- async def run_hooks_async(self, is_exit: bool = False):
160
+ async def run_hooks_async(self, is_exit: bool = False) -> None:
161
161
  """Run extensions asynchronously with support for sync lifecycle hooks.
162
162
 
163
163
  The ``is_exit`` flag is required as a `StopIteration` cannot be raised from
@@ -4,7 +4,7 @@ import dataclasses
4
4
  import time
5
5
  from datetime import datetime
6
6
  from inspect import isawaitable
7
- from typing import TYPE_CHECKING, Any, Dict, List, Optional
7
+ from typing import TYPE_CHECKING, Any, Dict, Generator, List, Optional
8
8
 
9
9
  from strawberry.extensions import SchemaExtension
10
10
  from strawberry.extensions.utils import get_path_from_info
@@ -81,19 +81,19 @@ class ApolloTracingExtension(SchemaExtension):
81
81
  self._resolver_stats: List[ApolloResolverStats] = []
82
82
  self.execution_context = execution_context
83
83
 
84
- def on_operation(self):
84
+ def on_operation(self) -> Generator[None, None, None]:
85
85
  self.start_timestamp = self.now()
86
86
  self.start_time = datetime.utcnow()
87
87
  yield
88
88
  self.end_timestamp = self.now()
89
89
  self.end_time = datetime.utcnow()
90
90
 
91
- def on_parse(self):
91
+ def on_parse(self) -> Generator[None, None, None]:
92
92
  self._start_parsing = self.now()
93
93
  yield
94
94
  self._end_parsing = self.now()
95
95
 
96
- def on_validate(self):
96
+ def on_validate(self) -> Generator[None, None, None]:
97
97
  self._start_validation = self.now()
98
98
  yield
99
99
  self._end_validation = self.now()
@@ -118,10 +118,10 @@ class ApolloTracingExtension(SchemaExtension):
118
118
  ),
119
119
  )
120
120
 
121
- def get_results(self):
121
+ def get_results(self) -> Dict[str, Dict[str, Any]]:
122
122
  return {"tracing": self.stats.to_json()}
123
123
 
124
- async def resolve(self, _next, root, info, *args, **kwargs):
124
+ async def resolve(self, _next, root, info, *args, **kwargs) -> Any:
125
125
  if should_skip_tracing(_next, info):
126
126
  result = _next(root, info, *args, **kwargs)
127
127
 
@@ -154,7 +154,7 @@ class ApolloTracingExtension(SchemaExtension):
154
154
 
155
155
 
156
156
  class ApolloTracingExtensionSync(ApolloTracingExtension):
157
- def resolve(self, _next, root, info, *args, **kwargs):
157
+ def resolve(self, _next, root, info, *args, **kwargs) -> Any:
158
158
  if should_skip_tracing(_next, info):
159
159
  return _next(root, info, *args, **kwargs)
160
160
 
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import hashlib
4
4
  from inspect import isawaitable
5
- from typing import TYPE_CHECKING, Iterator, Optional
5
+ from typing import TYPE_CHECKING, Any, Generator, Iterator, Optional
6
6
 
7
7
  from ddtrace import tracer
8
8
 
@@ -34,7 +34,7 @@ class DatadogTracingExtension(SchemaExtension):
34
34
 
35
35
  return query_hash
36
36
 
37
- def hash_query(self, query: str):
37
+ def hash_query(self, query: str) -> str:
38
38
  return hashlib.md5(query.encode("utf-8")).hexdigest()
39
39
 
40
40
  def on_operation(self) -> Iterator[None]:
@@ -64,17 +64,17 @@ class DatadogTracingExtension(SchemaExtension):
64
64
  yield
65
65
  self.request_span.finish()
66
66
 
67
- def on_validate(self):
67
+ def on_validate(self) -> Generator[None, None, None]:
68
68
  self.validation_span = tracer.trace("Validation", span_type="graphql")
69
69
  yield
70
70
  self.validation_span.finish()
71
71
 
72
- def on_parse(self):
72
+ def on_parse(self) -> Generator[None, None, None]:
73
73
  self.parsing_span = tracer.trace("Parsing", span_type="graphql")
74
74
  yield
75
75
  self.parsing_span.finish()
76
76
 
77
- async def resolve(self, _next, root, info, *args, **kwargs):
77
+ async def resolve(self, _next, root, info, *args, **kwargs) -> Any:
78
78
  if should_skip_tracing(_next, info):
79
79
  result = _next(root, info, *args, **kwargs)
80
80
 
@@ -100,7 +100,7 @@ class DatadogTracingExtension(SchemaExtension):
100
100
 
101
101
 
102
102
  class DatadogTracingExtensionSync(DatadogTracingExtension):
103
- def resolve(self, _next, root, info, *args, **kwargs):
103
+ def resolve(self, _next, root, info, *args, **kwargs) -> Any:
104
104
  if should_skip_tracing(_next, info):
105
105
  return _next(root, info, *args, **kwargs)
106
106
 
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  import enum
4
4
  from copy import deepcopy
5
5
  from inspect import isawaitable
6
- from typing import TYPE_CHECKING, Any, Callable, Dict, Optional
6
+ from typing import TYPE_CHECKING, Any, Callable, Dict, Generator, Optional
7
7
 
8
8
  from opentelemetry import trace
9
9
  from opentelemetry.trace import SpanKind
@@ -47,7 +47,7 @@ class OpenTelemetryExtension(SchemaExtension):
47
47
  if execution_context:
48
48
  self.execution_context = execution_context
49
49
 
50
- def on_operation(self):
50
+ def on_operation(self) -> Generator[None, None, None]:
51
51
  self._operation_name = self.execution_context.operation_name
52
52
  span_name = (
53
53
  f"GraphQL Query: {self._operation_name}"
@@ -76,7 +76,7 @@ class OpenTelemetryExtension(SchemaExtension):
76
76
  self._span_holder[RequestStage.REQUEST].update_name(span_name)
77
77
  self._span_holder[RequestStage.REQUEST].end()
78
78
 
79
- def on_validate(self):
79
+ def on_validate(self) -> Generator[None, None, None]:
80
80
  ctx = trace.set_span_in_context(self._span_holder[RequestStage.REQUEST])
81
81
  self._span_holder[RequestStage.VALIDATION] = self._tracer.start_span(
82
82
  "GraphQL Validation",
@@ -85,7 +85,7 @@ class OpenTelemetryExtension(SchemaExtension):
85
85
  yield
86
86
  self._span_holder[RequestStage.VALIDATION].end()
87
87
 
88
- def on_parse(self):
88
+ def on_parse(self) -> Generator[None, None, None]:
89
89
  ctx = trace.set_span_in_context(self._span_holder[RequestStage.REQUEST])
90
90
  self._span_holder[RequestStage.PARSING] = self._tracer.start_span(
91
91
  "GraphQL Parsing", context=ctx
@@ -101,7 +101,9 @@ class OpenTelemetryExtension(SchemaExtension):
101
101
  return args
102
102
  return self._arg_filter(deepcopy(args), info)
103
103
 
104
- def add_tags(self, span: Span, info: GraphQLResolveInfo, kwargs: Dict[str, Any]):
104
+ def add_tags(
105
+ self, span: Span, info: GraphQLResolveInfo, kwargs: Dict[str, Any]
106
+ ) -> None:
105
107
  graphql_path = ".".join(map(str, get_path_from_info(info)))
106
108
 
107
109
  span.set_attribute("component", "graphql")
@@ -114,7 +116,7 @@ class OpenTelemetryExtension(SchemaExtension):
114
116
  for kwarg, value in filtered_kwargs.items():
115
117
  span.set_attribute(f"graphql.param.{kwarg}", value)
116
118
 
117
- async def resolve(self, _next, root, info, *args, **kwargs):
119
+ async def resolve(self, _next, root, info, *args, **kwargs) -> Any:
118
120
  if should_skip_tracing(_next, info):
119
121
  result = _next(root, info, *args, **kwargs)
120
122
 
@@ -137,7 +139,7 @@ class OpenTelemetryExtension(SchemaExtension):
137
139
 
138
140
 
139
141
  class OpenTelemetryExtensionSync(OpenTelemetryExtension):
140
- def resolve(self, _next, root, info, *args, **kwargs):
142
+ def resolve(self, _next, root, info, *args, **kwargs) -> Any:
141
143
  if should_skip_tracing(_next, info):
142
144
  result = _next(root, info, *args, **kwargs)
143
145
 
@@ -318,7 +318,7 @@ class GraphQLRouter(APIRouter):
318
318
  operation_name: Optional[str] = None,
319
319
  root_value: Any = None,
320
320
  allowed_operation_types: Optional[Iterable[OperationType]] = None,
321
- ):
321
+ ) -> ExecutionResult:
322
322
  if self.debug and query:
323
323
  pretty_print_graphql_operation(operation_name, query, variables)
324
324
 
@@ -10,7 +10,7 @@ else:
10
10
  _T = TypeVar("_T", bound=type)
11
11
 
12
12
 
13
- def identity(x): # pragma: no cover
13
+ def identity(x: _T) -> _T: # pragma: no cover
14
14
  return x
15
15
 
16
16
 
@@ -171,7 +171,7 @@ class Schema(BaseSchema):
171
171
  self._schema.query_type = query_type
172
172
  self._schema.type_map[query_type.name] = query_type
173
173
 
174
- def entities_resolver(self, root, info, representations):
174
+ def entities_resolver(self, root, info, representations) -> List[object]:
175
175
  results = []
176
176
 
177
177
  for representation in representations:
@@ -342,6 +342,13 @@ class Schema(BaseSchema):
342
342
  resolve=self.entities_resolver,
343
343
  )
344
344
 
345
+ def _warn_for_federation_directives(self) -> None:
346
+ # this is used in the main schema to raise if there's a directive
347
+ # that's for federation, but in this class we don't want to warn,
348
+ # since it is expected to have federation directives
349
+
350
+ pass
351
+
345
352
 
346
353
  def _get_entity_type(type_map: "TypeMap"):
347
354
  # https://www.apollographql.com/docs/apollo-server/federation/federation-spec/#resolve-requests-for-entities
@@ -1,5 +1,5 @@
1
1
  import dataclasses
2
- from typing import List, Optional, Type, TypeVar
2
+ from typing import Callable, List, Optional, Type, TypeVar
3
3
 
4
4
  from strawberry.directive import directive_field
5
5
  from strawberry.field import StrawberryField, field
@@ -36,7 +36,7 @@ def schema_directive(
36
36
  print_definition: bool = True,
37
37
  compose: bool = False,
38
38
  import_url: Optional[str] = None,
39
- ):
39
+ ) -> Callable[..., T]:
40
40
  def _wrap(cls: T) -> T:
41
41
  cls = _wrap_dataclass(cls)
42
42
  fields = _get_fields(cls)
@@ -320,7 +320,7 @@ def print_enum(
320
320
  )
321
321
 
322
322
 
323
- def print_extends(type_, schema: BaseSchema):
323
+ def print_extends(type_, schema: BaseSchema) -> str:
324
324
  from strawberry.schema.schema_converter import GraphQLCoreConverter
325
325
 
326
326
  strawberry_type = type_.extensions and type_.extensions.get(
@@ -18,6 +18,7 @@ class StrawberrySanicContext(TypedDict):
18
18
  "Accessing context attributes via the dot notation is deprecated, "
19
19
  "please use context.get('key') or context['key'] instead",
20
20
  DeprecationWarning,
21
+ stacklevel=2,
21
22
  )
22
23
 
23
24
  return super().__getitem__(key)
strawberry/sanic/views.py CHANGED
@@ -69,17 +69,19 @@ class GraphQLView(HTTPMethodView):
69
69
  warnings.warn(
70
70
  "json_encoder is deprecated, override encode_json instead",
71
71
  DeprecationWarning,
72
+ stacklevel=2,
72
73
  )
73
74
 
74
75
  if self.json_dumps_params is not None:
75
76
  warnings.warn(
76
77
  "json_dumps_params is deprecated, override encode_json instead",
77
78
  DeprecationWarning,
79
+ stacklevel=2,
78
80
  )
79
81
 
80
82
  self.json_encoder = json.JSONEncoder
81
83
 
82
- def get_root_value(self):
84
+ def get_root_value(self) -> Any:
83
85
  return None
84
86
 
85
87
  async def get_context(
strawberry/schema/base.py CHANGED
@@ -62,7 +62,7 @@ class BaseSchema(Protocol):
62
62
  context_value: Optional[Any] = None,
63
63
  root_value: Optional[Any] = None,
64
64
  operation_name: Optional[str] = None,
65
- ):
65
+ ) -> Any:
66
66
  raise NotImplementedError
67
67
 
68
68
  @abstractmethod
@@ -101,7 +101,7 @@ class NameConverter:
101
101
 
102
102
  for type_ in union.types:
103
103
  if isinstance(type_, LazyType):
104
- type_ = cast("StrawberryType", type_.resolve_type())
104
+ type_ = cast("StrawberryType", type_.resolve_type()) # noqa: PLW2901
105
105
 
106
106
  if hasattr(type_, "_type_definition"):
107
107
  type_name = self.from_type(type_._type_definition)
@@ -2,7 +2,18 @@ from __future__ import annotations
2
2
 
3
3
  import warnings
4
4
  from functools import lru_cache
5
- from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Type, Union, cast
5
+ from typing import (
6
+ TYPE_CHECKING,
7
+ Any,
8
+ AsyncIterator,
9
+ Dict,
10
+ Iterable,
11
+ List,
12
+ Optional,
13
+ Type,
14
+ Union,
15
+ cast,
16
+ )
6
17
 
7
18
  from graphql import (
8
19
  GraphQLNamedType,
@@ -34,6 +45,7 @@ from .execute import execute, execute_sync
34
45
 
35
46
  if TYPE_CHECKING:
36
47
  from graphql import ExecutionContext as GraphQLExecutionContext
48
+ from graphql import ExecutionResult as GraphQLExecutionResult
37
49
 
38
50
  from strawberry.custom_scalar import ScalarDefinition, ScalarWrapper
39
51
  from strawberry.directive import StrawberryDirective
@@ -114,7 +126,7 @@ class Schema(BaseSchema):
114
126
  else:
115
127
  if hasattr(type_, "_type_definition"):
116
128
  if type_._type_definition.is_generic:
117
- type_ = StrawberryAnnotation(type_).resolve()
129
+ type_ = StrawberryAnnotation(type_).resolve() # noqa: PLW2901
118
130
  graphql_type = self.schema_converter.from_maybe_optional(type_)
119
131
  if isinstance(graphql_type, GraphQLNonNull):
120
132
  graphql_type = graphql_type.of_type
@@ -283,7 +295,7 @@ class Schema(BaseSchema):
283
295
  context_value: Optional[Any] = None,
284
296
  root_value: Optional[Any] = None,
285
297
  operation_name: Optional[str] = None,
286
- ):
298
+ ) -> Union[AsyncIterator[GraphQLExecutionResult], GraphQLExecutionResult]:
287
299
  return await subscribe(
288
300
  self._schema,
289
301
  parse(query),
@@ -297,19 +309,23 @@ class Schema(BaseSchema):
297
309
  """Raises a warning if the schema has any federation directives."""
298
310
  from strawberry.federation.schema_directives import FederationDirective
299
311
 
312
+ all_types = self.schema_converter.type_map.values()
313
+ all_type_defs = (type_.definition for type_ in all_types)
314
+
315
+ all_directives = (
316
+ directive
317
+ for type_def in all_type_defs
318
+ for directive in (type_def.directives or [])
319
+ )
320
+
300
321
  if any(
301
- type_
302
- for type_ in self.schema_converter.type_map.values()
303
- if any(
304
- directive
305
- for directive in (type_.definition.directives or [])
306
- if isinstance(directive, FederationDirective)
307
- )
322
+ isinstance(directive, FederationDirective) for directive in all_directives
308
323
  ):
309
324
  warnings.warn(
310
325
  "Federation directive found in schema. "
311
- "Should use strawberry.federation.Schema instead.",
326
+ "Use `strawberry.federation.Schema` instead of `strawberry.Schema`.",
312
327
  UserWarning,
328
+ stacklevel=3,
313
329
  )
314
330
 
315
331
  def as_str(self) -> str:
@@ -762,7 +762,7 @@ class GraphQLCoreConverter:
762
762
  # both lazy types are always resolved because two different lazy types
763
763
  # may be referencing the same actual type
764
764
  if isinstance(type1, LazyType):
765
- type1 = type1.resolve_type()
765
+ type1 = type1.resolve_type() # noqa: PLW2901
766
766
  elif isinstance(type1, StrawberryOptional) and isinstance(
767
767
  type1.of_type, LazyType
768
768
  ):
@@ -1,6 +1,6 @@
1
1
  import dataclasses
2
2
  from enum import Enum
3
- from typing import List, Optional, Type, TypeVar
3
+ from typing import Callable, List, Optional, Type, TypeVar
4
4
 
5
5
  from strawberry.object_type import _wrap_dataclass
6
6
  from strawberry.types.type_resolver import _get_fields
@@ -51,7 +51,7 @@ def schema_directive(
51
51
  name: Optional[str] = None,
52
52
  repeatable: bool = False,
53
53
  print_definition: bool = True,
54
- ):
54
+ ) -> Callable[..., T]:
55
55
  def _wrap(cls: T) -> T:
56
56
  cls = _wrap_dataclass(cls)
57
57
  fields = _get_fields(cls)
@@ -77,7 +77,7 @@ class BaseGraphQLTransportWSHandler(ABC):
77
77
  self.connection_init_timeout_task = asyncio.create_task(timeout_handler)
78
78
  return await self.handle_request()
79
79
 
80
- async def handle_connection_init_timeout(self):
80
+ async def handle_connection_init_timeout(self) -> None:
81
81
  delay = self.connection_init_wait_timeout.total_seconds()
82
82
  await asyncio.sleep(delay=delay)
83
83
 
@@ -87,7 +87,7 @@ class BaseGraphQLTransportWSHandler(ABC):
87
87
  reason = "Connection initialisation timeout"
88
88
  await self.close(code=4408, reason=reason)
89
89
 
90
- async def handle_message(self, message: dict):
90
+ async def handle_message(self, message: dict) -> None:
91
91
  handler: Callable
92
92
  handler_arg: Any
93
93
  try:
strawberry/test/client.py CHANGED
@@ -56,7 +56,7 @@ class BaseGraphQLTestClient(ABC):
56
56
  body: Dict[str, object],
57
57
  headers: Optional[Dict[str, object]] = None,
58
58
  files: Optional[Dict[str, object]] = None,
59
- ):
59
+ ) -> Any:
60
60
  raise NotImplementedError
61
61
 
62
62
  def _build_body(
@@ -29,6 +29,8 @@ def merge_types(name: str, types: Tuple[type, ...]) -> type:
29
29
  counter = Counter(f.name for f in fields)
30
30
  dupes = [f for f, c in counter.most_common() if c > 1]
31
31
  if dupes:
32
- warnings.warn("{} has overridden fields: {}".format(name, ", ".join(dupes)))
32
+ warnings.warn(
33
+ "{} has overridden fields: {}".format(name, ", ".join(dupes)), stacklevel=2
34
+ )
33
35
 
34
36
  return strawberry.type(type(name, types, {}))
@@ -125,7 +125,7 @@ class ReservedType(NamedTuple):
125
125
  "their respective types (i.e. use value: 'DirectiveValue[str]' instead "
126
126
  "of 'value: str' and 'info: Info' instead of a plain 'info')."
127
127
  )
128
- warnings.warn(warning)
128
+ warnings.warn(warning, stacklevel=3)
129
129
  return reserved_name
130
130
  else:
131
131
  return None
strawberry/types/info.py CHANGED
@@ -41,6 +41,7 @@ class Info(Generic[ContextType, RootValueType]):
41
41
  warnings.warn(
42
42
  "`info.field_nodes` is deprecated, use `selected_fields` instead",
43
43
  DeprecationWarning,
44
+ stacklevel=2,
44
45
  )
45
46
 
46
47
  return self._raw_info.field_nodes
@@ -157,7 +157,7 @@ def _get_fields(cls: Type) -> List[StrawberryField]:
157
157
  )
158
158
 
159
159
  # Create a StrawberryField, for fields of Types #1 and #2a
160
- field = StrawberryField(
160
+ field = StrawberryField( # noqa: PLW2901
161
161
  python_name=field.name,
162
162
  graphql_name=None,
163
163
  type_annotation=StrawberryAnnotation(
@@ -1,5 +1,5 @@
1
1
  import inspect
2
- from typing import AsyncIterator, Awaitable, Iterator, TypeVar, Union
2
+ from typing import AsyncIterator, Awaitable, Iterator, TypeVar, Union, cast
3
3
 
4
4
  T = TypeVar("T")
5
5
 
@@ -7,8 +7,8 @@ AwaitableOrValue = Union[Awaitable[T], T]
7
7
  AsyncIteratorOrIterator = Union[AsyncIterator[T], Iterator[T]]
8
8
 
9
9
 
10
- async def await_maybe(value: AwaitableOrValue):
10
+ async def await_maybe(value: AwaitableOrValue[T]) -> T:
11
11
  if inspect.isawaitable(value):
12
12
  return await value
13
13
 
14
- return value
14
+ return cast(T, value)
@@ -13,7 +13,7 @@ from typing import Any
13
13
  from strawberry.ext.dataclasses.dataclasses import dataclass_init_fn
14
14
 
15
15
 
16
- def add_custom_init_fn(cls: Any):
16
+ def add_custom_init_fn(cls: Any) -> None:
17
17
  fields = [
18
18
  f
19
19
  for f in getattr(cls, _FIELDS).values()
strawberry/utils/debug.py CHANGED
@@ -11,7 +11,7 @@ class StrawberryJSONEncoder(JSONEncoder):
11
11
 
12
12
  def pretty_print_graphql_operation(
13
13
  operation_name: Optional[str], query: str, variables: Optional[Dict["str", Any]]
14
- ):
14
+ ) -> None:
15
15
  """Pretty print a GraphQL operation using pygments.
16
16
 
17
17
  Won't print introspection operation to prevent noise in the output."""
@@ -1,11 +1,11 @@
1
1
  import inspect
2
2
  from functools import lru_cache
3
- from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload
3
+ from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload
4
4
  from typing_extensions import Literal, get_args
5
5
 
6
6
 
7
7
  @lru_cache(maxsize=250)
8
- def get_func_args(func: Callable[[Any], Any]):
8
+ def get_func_args(func: Callable[[Any], Any]) -> List[str]:
9
9
  """Returns a list of arguments for the function"""
10
10
 
11
11
  sig = inspect.signature(func)
@@ -27,7 +27,7 @@ def get_operation_type(
27
27
 
28
28
  if operation_name:
29
29
  for d in graphql_document.definitions:
30
- d = cast(OperationDefinitionNode, d)
30
+ d = cast(OperationDefinitionNode, d) # noqa: PLW2901
31
31
  if d.name and d.name.value == operation_name:
32
32
  definition = d
33
33
  break
@@ -161,7 +161,7 @@ def is_type_var(annotation: Type) -> bool:
161
161
  return isinstance(annotation, TypeVar)
162
162
 
163
163
 
164
- def get_parameters(annotation: Type):
164
+ def get_parameters(annotation: Type) -> Union[Tuple[object], Tuple[()]]:
165
165
  if (
166
166
  isinstance(annotation, _GenericAlias)
167
167
  or isinstance(annotation, type)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: strawberry-graphql
3
- Version: 0.166.0
3
+ Version: 0.167.1
4
4
  Summary: A library for creating GraphQL APIs
5
5
  Home-page: https://strawberry.rocks/
6
6
  License: MIT