Skip to content

Commit

Permalink
Fix @plugin.inject_dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
hypergonial committed Dec 29, 2023
1 parent 41012a7 commit 71114a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 10 additions & 7 deletions arc/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,23 +237,26 @@ def load(client: arc.GatewayClient) -> None:
- [`Client.set_type_dependency`][arc.client.Client.set_type_dependency]
A method to set dependencies for the client.
"""
if self._client is None:
raise RuntimeError(
f"Cannot inject dependencies into '{func.__name__}' before plugin '{self.name}' is included in a client."
)

if inspect.iscoroutinefunction(func):

@functools.wraps(func)
async def decorator_async(*args: P.args, **kwargs: P.kwargs) -> T:
return await self.client.injector.call_with_async_di(func, *args, **kwargs)
if self._client is None:
raise RuntimeError(
f"Cannot inject dependencies into '{func.__name__}' before plugin '{self.name}' is included in a client."
)
return await self._client.injector.call_with_async_di(func, *args, **kwargs)

return decorator_async # pyright: ignore reportGeneralTypeIssues
else:

@functools.wraps(func)
def decorator(*args: P.args, **kwargs: P.kwargs) -> T:
return self.client.injector.call_with_di(func, *args, **kwargs)
if self._client is None:
raise RuntimeError(
f"Cannot inject dependencies into '{func.__name__}' before plugin '{self.name}' is included in a client."
)
return self._client.injector.call_with_di(func, *args, **kwargs)

return decorator

Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ hide:

Here you can find all the changelogs for `hikari-arc`.

<!--TODO: Remove arc.Injected[T] because it's confusing -->
## v0.1.4

- Add support for passing mappings to `choices=` when specifying option params.
- Improve handling missing responses via REST by adding `NoResponseIssuedError`.
- Fix `@plugin.inject_dependencies` failing when located outside of the main module.

## v0.1.3

Expand Down

0 comments on commit 71114a6

Please sign in to comment.