Repository navigation
fix: return None from the descriptor property when there are none - #230
Merged
Merged
Conversation
The descriptor property is typed ndarray | None, but its array_result decorator called len() on the value, so it raised TypeError for features with no descriptors. It now returns None, and keeps the single-feature behaviour of giving a 1D vector. With the property honestly typed, match() checks both sets have descriptors and raises a clear ValueError, as distance() already does, and descriptor1 and descriptor2 of a FeatureMatch are typed as possibly None. The xfail test that recorded the bug is now an ordinary test, and a second test covers match(). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| 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
The
descriptorproperty of a feature set is typednp.ndarray | None, but it was wrapped in@array_result, which callslen()on the value. So for features with no descriptors (for example aHarrisset built by hand, or any set made without them)features.descriptorraisedTypeError: object of type 'NoneType' has no len()instead of returningNone.It now returns
Nonein that case, and keeps the existing behaviour otherwise: a 1D vector for a single feature, and an N × M array for several. Its docstring says so, with a.. versionchanged:: 2.5.0note.Because the property now has its honest type, mypy found three places that assumed it was never
None:match()now checks that both sets have descriptors and raisesValueError("features have no descriptors"), asdistance()already does. Before, it failed with anAttributeErroronNone.FeatureMatch.descriptor1anddescriptor2are typed as lists of arrays that may beNone.Found by the new point-feature tests (PR 221), which recorded the
TypeErroras a strictxfailtest. That test is now an ordinary test, and a second one covers thematch()error.Testing
pytest tests: 1854 passed, 33 skipped, 12 xfailed (eachxfailbelongs to a different bug).mypyreports no issues. Not run: CI on Windows or OpenCV 4 (CI will).This change was written with AI assistance (Claude Code) and the diff has been read by the maintainer.
🤖 Generated with Claude Code