From fe42996f487ef053cb060594cfa1ef9fd8d08935 Mon Sep 17 00:00:00 2001 From: tandemdude <43570299+tandemdude@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:15:49 +0100 Subject: [PATCH] chore: add remaining coverage --- lightbulb/di/container.py | 2 -- tests/di/test_container.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lightbulb/di/container.py b/lightbulb/di/container.py index a3e34b4c..f6514608 100644 --- a/lightbulb/di/container.py +++ b/lightbulb/di/container.py @@ -240,8 +240,6 @@ async def _get(self, dependency_id: str, *, allow_missing: bool = False) -> t.An for sub_dependency_id, param_name in node_data["factory_params"].items(): sub_dependency = await node_data["container"]._get(sub_dependency_id, allow_missing=allow_missing) if sub_dependency is _MISSING: - # I'm not sure that this branch can actually be hit, but I'm going to leave it here - # just in case... return _MISSING sub_dependencies[param_name] = sub_dependency diff --git a/tests/di/test_container.py b/tests/di/test_container.py index 657e73b1..6b2e6ecb 100644 --- a/tests/di/test_container.py +++ b/tests/di/test_container.py @@ -414,3 +414,20 @@ async def test__contains__returns_true_when_dependency_known_by_parent(self) -> async with di.Container(r1) as r1, di.Container(r2, parent=r1) as r2: assert object in r2 + + @pytest.mark.asyncio + async def test_parent_dependency_returns_default_if_given_and_depends_on_child_dependency(self) -> None: + def f(_: A) -> object: + return object() + + parent_registry = di.Registry() + parent_registry.register_factory(B, f) + + child_registry = di.Registry() + child_registry.register_factory(A, lambda: object()) + + async with ( + di.Container(parent_registry) as pc, + di.Container(child_registry, parent=pc) as cc, + ): + assert await cc.get(B, default=None) is None