Skip to content

Commit

Permalink
chore: add remaining coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tandemdude committed Aug 22, 2024
1 parent ac4acc3 commit fe42996
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lightbulb/di/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/di/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fe42996

Please sign in to comment.