Skip to content

Commit

Permalink
fix Container.default_extensions default value coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirVondukr committed Nov 21, 2024
1 parent 04cee43 commit da3b56c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion aioinject/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ def __init__(
*,
default_extensions: Sequence[Extension] | None = None,
) -> None:
default_extensions = default_extensions or DEFAULT_EXTENSIONS
default_extensions = (
default_extensions
if default_extensions is not None
else DEFAULT_EXTENSIONS
)

self._exit_stack = AsyncExitStack()
self._singletons = SingletonStore(exit_stack=self._exit_stack)
Expand Down
11 changes: 11 additions & 0 deletions tests/container/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,14 @@ def dependency() -> Iterator[int]:

assert shutdown is False
assert shutdown is True


def test_dependency_extractor_not_found() -> None:
provider = Singleton(_ServiceA)
container = Container(default_extensions=[])
with pytest.raises(ValueError) as err_info: # noqa: PT011
container.register(provider)
assert (
str(err_info.value)
== f"Couldn't find appropriate SupportsDependencyExtraction extension for provider {provider!r}"
)

0 comments on commit da3b56c

Please sign in to comment.