Skip to content

Commit 97b127a

Browse files
author
remimd
committed
Revert last 2 commits 🚑️
1 parent 58961ce commit 97b127a

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

injection/_core/module.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,6 @@ def __str__(self) -> str:
156156
)
157157

158158

159-
@dataclass(frozen=True, slots=True)
160-
class UnlockCalled(Event):
161-
def __str__(self) -> str:
162-
return "An `unlock` method has been called."
163-
164-
165159
"""
166160
Broker
167161
"""
@@ -808,11 +802,8 @@ def change_priority(self, module: Module, priority: Priority | PriorityStr) -> S
808802
return self
809803

810804
def unlock(self) -> Self:
811-
event = UnlockCalled()
812-
813-
with self.dispatch(event, lock_bypass=True):
814-
for broker in self.__brokers:
815-
broker.unlock()
805+
for broker in self.__brokers:
806+
broker.unlock()
816807

817808
return self
818809

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

850841
@contextmanager
851-
def dispatch(self, event: Event, *, lock_bypass: bool = False) -> Iterator[None]:
852-
if not lock_bypass:
853-
self.__check_locking()
842+
def dispatch(self, event: Event) -> Iterator[None]:
843+
self.__check_locking()
854844

855845
with self.__channel.dispatch(event):
856846
try:

tests/core/test_module.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,25 @@ class C(A): ...
405405
assert isinstance(b1.a, A)
406406
assert isinstance(b2.a, C)
407407

408+
def test_unlock_with_locked_module_in_use(self, module):
409+
second_module = Module()
410+
module.use(second_module)
411+
412+
@module.singleton
413+
class A: ...
414+
415+
@second_module.singleton
416+
class B: ...
417+
418+
a = module.get_instance(A)
419+
b = module.get_instance(B)
420+
421+
module.unlock()
422+
assert a is not module.get_instance(A)
423+
assert b is not module.get_instance(B)
424+
425+
# TODO: not yet implemented
426+
@pytest.mark.skip
408427
def test_unlock_with_module_in_use_raise_module_lock_error(self, module):
409428
second_module = Module()
410429
module.use(second_module)

0 commit comments

Comments
 (0)