Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions injection/_core/common/asynchronous.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import asyncio
from abc import abstractmethod
from collections.abc import Awaitable, Callable, Generator
from dataclasses import dataclass
from typing import Any, NoReturn, Protocol, runtime_checkable
from typing import Any, Protocol, runtime_checkable


@dataclass(repr=False, eq=False, frozen=True, slots=True)
Expand Down Expand Up @@ -32,10 +33,16 @@ class AsyncCaller[**P, T](Caller[P, T]):
async def acall(self, /, *args: P.args, **kwargs: P.kwargs) -> T:
return await self.callable(*args, **kwargs)

def call(self, /, *args: P.args, **kwargs: P.kwargs) -> NoReturn:
raise RuntimeError(
"Synchronous call isn't supported for an asynchronous Callable."
)
def call(self, /, *args: P.args, **kwargs: P.kwargs) -> T:
loop = asyncio.get_event_loop()

if loop.is_running():
raise RuntimeError(
"Can't call an asynchronous function in a synchronous context."
)

coroutine = self.callable(*args, **kwargs)
return loop.run_until_complete(coroutine)


@dataclass(repr=False, eq=False, frozen=True, slots=True)
Expand Down
4 changes: 2 additions & 2 deletions injection/_core/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def __str__(self) -> str:
length = len(self.classes)
formatted_types = ", ".join(f"`{cls}`" for cls in self.classes)
return (
f"{length} dependenc{"ies" if length > 1 else "y"} have been "
f"updated{f": {formatted_types}" if formatted_types else ""}."
f"{length} dependenc{'ies' if length > 1 else 'y'} have been "
f"updated{f': {formatted_types}' if formatted_types else ''}."
)


Expand Down
44 changes: 22 additions & 22 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading