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
18 changes: 4 additions & 14 deletions injection/_core/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,6 @@ def __str__(self) -> str:
)


@dataclass(frozen=True, slots=True)
class UnlockCalled(Event):
def __str__(self) -> str:
return "An `unlock` method has been called."


"""
Broker
"""
Expand Down Expand Up @@ -808,11 +802,8 @@ def change_priority(self, module: Module, priority: Priority | PriorityStr) -> S
return self

def unlock(self) -> Self:
event = UnlockCalled()

with self.dispatch(event, lock_bypass=True):
for broker in self.__brokers:
broker.unlock()
for broker in self.__brokers:
broker.unlock()

return self

Expand Down Expand Up @@ -848,9 +839,8 @@ def on_event(self, event: Event, /) -> ContextManager[None]:
return self.dispatch(self_event)

@contextmanager
def dispatch(self, event: Event, *, lock_bypass: bool = False) -> Iterator[None]:
if not lock_bypass:
self.__check_locking()
def dispatch(self, event: Event) -> Iterator[None]:
self.__check_locking()

with self.__channel.dispatch(event):
try:
Expand Down
19 changes: 19 additions & 0 deletions tests/core/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,25 @@ class C(A): ...
assert isinstance(b1.a, A)
assert isinstance(b2.a, C)

def test_unlock_with_locked_module_in_use(self, module):
second_module = Module()
module.use(second_module)

@module.singleton
class A: ...

@second_module.singleton
class B: ...

a = module.get_instance(A)
b = module.get_instance(B)

module.unlock()
assert a is not module.get_instance(A)
assert b is not module.get_instance(B)

# TODO: not yet implemented
@pytest.mark.skip
def test_unlock_with_module_in_use_raise_module_lock_error(self, module):
second_module = Module()
module.use(second_module)
Expand Down