Repository navigation
feat: make sum() work on feature sets and raise clear TypeErrors - #243
Merged
Merged
Conversation
BaseFeature2D.__radd__ accepted only [], so sum() of feature sets, which
starts from 0, raised ValueError("bad"). It now also accepts None and 0,
and raises TypeError with a message for anything else. __add__ raises
TypeError instead of failing an assert for something that is not a
feature set.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| ErrorProne | 3 high |
🟢 Metrics 24 complexity · 0 duplication
Metric Results Complexity 24 Duplication 0
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
sum()of feature sets did not work. Python'ssumstarts from0, sosum([f1, f2])callsf1.__radd__(0), andBaseFeature2D.__radd__accepted only[]and raisedValueError("bad")for anything else. Aggregating feature sets with[]and+=still works as before.__radd__now also acceptsNoneand0, sosum(list_of_feature_sets)works, for lists and generators. The inputs are not changed, andsum([f])returnsf.__radd__raisesTypeErrorwith a message that names the type and says what can be added ([],Noneor0), instead ofValueError("bad").__add__raisesTypeErrorwith a message for something that is not a feature set,[]orNone, instead of failing anassert. This changes the exception fromAssertionErrortoTypeError, which is what its docstring already said.__radd__example showssum, and there are.. versionchanged:: 2.5.0notes.Tests
New tests:
sumof three feature sets (count, descriptors, order, inputs unchanged),sumof one set and of a generator,sumof different feature types raisingTypeError,0andNoneon the left, and theTypeErrormessages forint,str,boolandlistoperands.tests/test_image_point_features_extra.pypasses (127 tests) and mypy reports no errors. I have not run the full suite locally. CI will.This change was written with AI assistance (Claude Code) and I have reviewed the diff.
🤖 Generated with Claude Code