Skip to content

fix: return None from the descriptor property when there are none - #230

Merged
petercorke merged 2 commits into
mainfrom
bug/descriptor-none
Nov 22, 2026
Merged

petercorke merged 2 commits into
mainfrom
bug/descriptor-none

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

The descriptor property of a feature set is typed np.ndarray | None, but it was wrapped in @array_result, which calls len() on the value. So for features with no descriptors (for example a Harris set built by hand, or any set made without them) features.descriptor raised TypeError: object of type 'NoneType' has no len() instead of returning None.

It now returns None in 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.0 note.

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 raises ValueError("features have no descriptors"), as distance() already does. Before, it failed with an AttributeError on None.
  • FeatureMatch.descriptor1 and descriptor2 are typed as lists of arrays that may be None.

Found by the new point-feature tests (PR 221), which recorded the TypeError as a strict xfail test. That test is now an ordinary test, and a second one covers the match() error.

Testing

pytest tests: 1854 passed, 33 skipped, 12 xfailed (each xfail belongs to a different bug). mypy reports 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

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>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

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.

@petercorke
petercorke merged commit 7950cce into main Nov 22, 2026
34 checks passed
@petercorke
petercorke deleted the bug/descriptor-none branch November 22, 2026 12:25
@github-actions github-actions Bot mentioned this pull request Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant