Skip to content
Merged
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
7 changes: 4 additions & 3 deletions cq/_core/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ def handlers_from(
yield _make_handle_function(factory)

def subscribe(self, input_type: type[I], factory: HandlerFactory[[I], O]) -> Self:
for key_type in _build_key_types(input_type):
entries = {key_type: factory for key_type in _build_key_types(input_type)}

for key_type in entries:
if key_type in self.__factories:
raise RuntimeError(
f"A handler is already registered for the input type: `{key_type}`."
)

self.__factories[key_type] = factory

self.__factories.update(entries)
return self


Expand Down
Loading