@@ -269,18 +269,12 @@ def __add__(self, other: Union[Tool, "Toolset", list[Tool]]) -> "Toolset":
269269 :raises ValueError: If the combination would result in duplicate tool names
270270 """
271271 if isinstance (other , Tool ):
272- combined_tools = self .tools + [other ]
273- elif isinstance (other , Toolset ):
272+ return Toolset ( tools = self .tools + [other ])
273+ if isinstance (other , Toolset ):
274274 return _ToolsetWrapper ([self , other ])
275- elif isinstance (other , list ) and all (isinstance (item , Tool ) for item in other ):
276- combined_tools = self .tools + other
277- else :
278- raise TypeError (f"Cannot add { type (other ).__name__ } to Toolset" )
279-
280- # Check for duplicates
281- _check_duplicate_tool_names (combined_tools )
282-
283- return Toolset (tools = combined_tools )
275+ if isinstance (other , list ) and all (isinstance (item , Tool ) for item in other ):
276+ return Toolset (tools = self .tools + other )
277+ raise TypeError (f"Cannot add { type (other ).__name__ } to Toolset" )
284278
285279 def __len__ (self ) -> int :
286280 """
@@ -312,9 +306,9 @@ def __init__(self, toolsets: list[Toolset]):
312306 self .toolsets = toolsets
313307 # Check for duplicate tool names across all toolsets
314308 all_tools = [tool for toolset in toolsets for tool in toolset ]
309+ # Don't call super().__init__() to avoid redundant duplicate check in __post_init__
310+ # We check here and set tools directly
315311 _check_duplicate_tool_names (all_tools )
316- super ().__init__ () # empty intentionally
317- # we override all methods and manage toolsets directly here
318312 self .tools = all_tools
319313
320314 def __iter__ (self ):
0 commit comments