diff --git a/injection/_core/module.py b/injection/_core/module.py index caa5832..58e77ec 100644 --- a/injection/_core/module.py +++ b/injection/_core/module.py @@ -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 """ @@ -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 @@ -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: diff --git a/tests/core/test_module.py b/tests/core/test_module.py index eb15436..14b6b30 100644 --- a/tests/core/test_module.py +++ b/tests/core/test_module.py @@ -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)