fixed logical error in parameter "hi" the bisect functions of the bin… #13900
+2
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe your change:
This update improves how the binary search function handles negative values passed to hi. Earlier, when hi was negative, the code reset it to len(sorted_collection), which ignored Python’s negative-index behavior.
The new logic adjusts hi by converting the negative index into its proper positive position. This makes the function behave more consistently with Python slicing rules.
What Changed
Added support for negative indexing in the hi parameter:
if hi < 0: hi = len(sorted_collection) + hi + 1This ensures the search range is interpreted correctly when callers use negative indices.
Checklist: