Skip to content

fix: make _ToolsetWrapper.__getitem__ support negative indices#11927

Open
Diwak4r wants to merge 1 commit into
deepset-ai:mainfrom
Diwak4r:fix/toolset-wrapper-negative-index
Open

fix: make _ToolsetWrapper.__getitem__ support negative indices#11927
Diwak4r wants to merge 1 commit into
deepset-ai:mainfrom
Diwak4r:fix/toolset-wrapper-negative-index

Conversation

@Diwak4r

@Diwak4r Diwak4r commented Jul 9, 2026

Copy link
Copy Markdown

Summary

  • _ToolsetWrapper.__getitem__ used a forward enumerate scan with if i == index that only worked for non-negative indices. Requesting a negative index (e.g. combined[-1]) raised IndexError, while the base Toolset.__getitem__ correctly handles negative indices via list(self)[index].
  • Mirror the base class implementation so combined toolsets behave consistently with a single Toolset.

Closes #11759

Test plan

  • Added test_wrapper_getitem_supports_negative_index and test_wrapper_getitem_out_of_range_raises in test/tools/test_toolset_wrapper.py.
  • Ran the full test/tools/test_toolset_wrapper.py suite: 16 passed.

The base Toolset.__getitem__ uses list(self)[index], which handles
negative indices, but _ToolsetWrapper used a forward enumerate scan
with i == index that only worked for non-negative indices. This made
combined_toolsets[-1] raise IndexError, inconsistent with Toolset.

Closes deepset-ai#11759
Copilot AI review requested due to automatic review settings July 9, 2026 07:37
@Diwak4r Diwak4r requested a review from a team as a code owner July 9, 2026 07:37
@Diwak4r Diwak4r requested review from julian-risch and removed request for a team July 9, 2026 07:37
@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

@Diwak4r is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_ToolsetWrapper.__getitem__ doesn't support negative indices, unlike Toolset

3 participants