Skip to content

Commit

Permalink
fix: bug with wire=False short circuiting too early
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangb committed Aug 3, 2022
1 parent 5e39928 commit bea5ace
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
8 changes: 0 additions & 8 deletions di/dependant/_dependant.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ def register_parameter(self, param: inspect.Parameter) -> DependantBase[Any]:
This method can return the same or a new instance of a Dependant to avoid modifying itself.
"""
if self.wire is False:
return Dependant[Any](
call=self.call,
scope=self.scope,
use_cache=self.use_cache,
wire=self.wire,
sync_to_thread=self.sync_to_thread,
)
call = self.call
if call is None and param.default is not param.empty:

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "di"
version = "0.69.1"
version = "0.69.2"
description = "Dependency injection toolkit"
authors = ["Adrian Garcia Badaracco <[email protected]>"]
readme = "README.md"
Expand Down
10 changes: 8 additions & 2 deletions tests/test_solving.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,16 @@ def __init__(self, arg) -> None: # type: ignore # for Pylance
def test_no_wire() -> None:
"""Specifying wire=False skips wiring on the dependency itself"""

def without_flag(dep: Annotated[CannotBeWired, Marker(wire=True)]) -> None:
...

def with_flag(dep: Annotated[CannotBeWired, Marker(wire=False)]) -> None:
...

container = Container()
with pytest.raises(WiringError):
container.solve(Dependant(CannotBeWired), scopes=[None])
container.solve(Dependant(CannotBeWired, wire=False), scopes=[None])
container.solve(Dependant(without_flag), scopes=[None])
container.solve(Dependant(with_flag), scopes=[None])


def test_wiring_from_binds() -> None:
Expand Down

0 comments on commit bea5ace

Please sign in to comment.