Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 23, 2024
1 parent 8185fc1 commit f0ae422
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions strawberry/extensions/base_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class LifecycleStep(Enum):


class SchemaExtension:

# to support extensions that still use the old signature
# we have an optional argument here for ease of initialization.
def __init__(
Expand Down Expand Up @@ -60,7 +59,9 @@ def resolve(
) -> AwaitableOrValue[object]:
return _next(root, info, *args, **kwargs)

def get_results(self, execution_context: ExecutionContext) -> AwaitableOrValue[Dict[str, Any]]:
def get_results(
self, execution_context: ExecutionContext
) -> AwaitableOrValue[Dict[str, Any]]:
return {}

@classmethod
Expand Down
14 changes: 10 additions & 4 deletions strawberry/extensions/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@

class WrappedHook(NamedTuple):
extension: SchemaExtension
hook: Callable[[ExecutionContext], Union[AsyncContextManager[None], ContextManager[None]]]
hook: Callable[
[ExecutionContext], Union[AsyncContextManager[None], ContextManager[None]]
]
is_async: bool


Expand All @@ -58,7 +60,9 @@ def __init_subclass__(cls) -> None:
LEGACY_ENTER: str
LEGACY_EXIT: str

def __init__(self, extensions: List[SchemaExtension], execution_context: ExecutionContext) -> None:
def __init__(
self, extensions: List[SchemaExtension], execution_context: ExecutionContext
) -> None:
self.hooks: List[WrappedHook] = []
self.execution_context = execution_context

Check warning on line 67 in strawberry/extensions/context.py

View check run for this annotation

Codecov / codecov/patch

strawberry/extensions/context.py#L67

Added line #L67 was not covered by tests
self.default_hook: Hook = getattr(SchemaExtension, self.HOOK_NAME)
Expand Down Expand Up @@ -178,7 +182,7 @@ def __enter__(self) -> None:
"failed to complete synchronously."
)
else:
self.exit_stack.enter_context(hook.hook(self.execution_context))
self.exit_stack.enter_context(hook.hook(self.execution_context))

Check warning on line 185 in strawberry/extensions/context.py

View check run for this annotation

Codecov / codecov/patch

strawberry/extensions/context.py#L185

Added line #L185 was not covered by tests

def __exit__(
self,
Expand All @@ -195,7 +199,9 @@ async def __aenter__(self) -> None:

for hook in self.hooks:
if hook.is_async:
await self.async_exit_stack.enter_async_context(hook.hook(self.execution_context)) # type: ignore
await self.async_exit_stack.enter_async_context(

Check warning on line 202 in strawberry/extensions/context.py

View check run for this annotation

Codecov / codecov/patch

strawberry/extensions/context.py#L202

Added line #L202 was not covered by tests
hook.hook(self.execution_context)
) # type: ignore
else:
self.async_exit_stack.enter_context(hook.hook(self.execution_context)) # type: ignore

Check warning on line 206 in strawberry/extensions/context.py

View check run for this annotation

Codecov / codecov/patch

strawberry/extensions/context.py#L206

Added line #L206 was not covered by tests

Expand Down
2 changes: 1 addition & 1 deletion strawberry/extensions/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_extensions_results_sync(self, ctx: ExecutionContext) -> Dict[str, Any]:
if inspect.iscoroutinefunction(extension.get_results):
msg = "Cannot use async extension hook during sync execution"
raise RuntimeError(msg)
data.update(cast(Dict[str, Any], extension.get_results(ctx)))
data.update(cast(Dict[str, Any], extension.get_results(ctx)))

Check warning on line 49 in strawberry/extensions/runner.py

View check run for this annotation

Codecov / codecov/patch

strawberry/extensions/runner.py#L49

Added line #L49 was not covered by tests

return data

Expand Down

0 comments on commit f0ae422

Please sign in to comment.