Skip to content

Commit 2b92cbf

Browse files
committed
simplify: use set-based deduplication in BaseCallbackManager.merge()
1 parent fb0bbca commit 2b92cbf

File tree

1 file changed

+5
-5
lines changed
  • libs/core/langchain_core/callbacks

1 file changed

+5
-5
lines changed

libs/core/langchain_core/callbacks/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -965,11 +965,11 @@ def merge(self, other: BaseCallbackManager) -> Self:
965965
# ['tag2', 'tag1']
966966
```
967967
""" # noqa: E501
968-
# Directly combine the handler lists without using add_handler
969-
# to preserve the distinction between handlers and inheritable_handlers
970-
combined_handlers = list(self.handlers) + list(other.handlers)
971-
combined_inheritable = list(self.inheritable_handlers) + list(
972-
other.inheritable_handlers
968+
# Combine handlers and inheritable_handlers separately, using sets
969+
# to deduplicate (order not preserved)
970+
combined_handlers = list(set(self.handlers) | set(other.handlers))
971+
combined_inheritable = list(
972+
set(self.inheritable_handlers) | set(other.inheritable_handlers)
973973
)
974974

975975
return self.__class__(

0 commit comments

Comments
 (0)