Skip to content

fix: add py.typed marker and make the package pass mypy - #176

Merged
petercorke merged 19 commits into
mainfrom
feat/py-typed
Nov 19, 2026
Merged

petercorke merged 19 commits into
mainfrom
feat/py-typed

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Closes #152. Also moves Issue #40 (adopt mypy) forward.

Adds the empty py.typed marker (confirmed present in the built wheel) so type checkers use MVTB's annotations. To make that safe, mypy now reports zero errors, down from 539.

Changes:

  • mypy configured in place of the unused pyright block
  • the Image mixins share a base class mypy can evaluate, with a check that Image conforms to the _ImageBase Protocol
  • methods that return the same class are typed Self

Real bugs found by the type check and fixed:

  • Image.convolve(border="pad", bordervalue!=0) raised NameError
  • FeatureMatch.by_id1() returned None on its first call, and by_id2() never matched
  • BundleAdjust.optimize(animate=True) raised NameError
  • mpl_styling() raised TypeError when defaults or kwargs was None
  • VisualServo referenced undefined names (Animate, plot, history)
  • Image.disp(cmap="name") with badcolor raised AttributeError
  • BaseFeature2D.draw() raised TypeError if fontsize was passed
  • BagOfWords.wwfv() returned None for non-1-D slices

Some third-party stub errors (open3d, OpenCV, rosbags) are silenced with # type: ignore. mypy is not yet in CI; that is a separate PR.

Tests: 1427 passed, 35 skipped. AI-assisted (Claude Code), commits carry a Co-Authored-By trailer.

🤖 Generated with Claude Code

petercorke and others added 16 commits November 18, 2026 14:00
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
mypy rejects a conditional expression in a base-class list, so all 15
mixins were treated as untyped. ImageMixinBase is the _ImageBase Protocol
for type checkers and object at run time.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- import findpeaks, plot_labelbox and DTYPE_ALIASES from their own modules
  (the package-level star imports are invisible to mypy; findpeaks was also
  seen as a module, not the function)
- declare _stats and _plane_stats in the _ImageBase Protocol
- ImageTensor.Tensor returns Self; quote the ImageReshape meshgrid self type
- np.vstack for the deprecated np.row_stack, PIL Resampling.LANCZOS,
  cv2.MSER.create, explicit SE3 import in mvtbtool

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…_ImageBase

- ImageIO: a named cmap string is now resolved before set_bad (it raised
  AttributeError for str); widen the cmap type
- imtool: declare the cs_image/colorspace globals; stop reusing val for a list
- ImageMultiview, ImageConstants, ImageColor, ImageWholeFeatures: stop
  reusing one name for a list and then an array; annotate numeric locals
- __init__: import findpeaks and meshgrid from their own modules
- ImageCore: TYPE_CHECKING-only function so mypy reports any _ImageBase
  member that Image does not implement

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…eatures

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
wwfv() now returns the vector for non-1-D slices instead of None;
Fiducial.draw() raises ValueError when intrinsics or pose are missing.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…or, base/shapes

BundleAdjust.optimize(animate=True) referred to undefined names and
raised NameError; it now plots the graph with self.plot().

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
mpl_styling() no longer raises TypeError when defaults or kwargs is
None, and idisp() handles colororder=None for colour images.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
convolve(border='pad', bordervalue!=0) raised NameError; it now pads,
filters and crops back. labels_binary() error path and rankfilter()
string ranks no longer reference undefined names. Removes the unused
_border_args_cv helper.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Methods that return a new image of the same class are now typed Self.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
FeatureMatch.by_id1() and by_id2() returned None on their first call,
and by_id2() indexed on the wrong column so it never matched. draw()
no longer raises TypeError when the caller passes fontsize.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Fixes references to undefined names (Animate, plot, history, pt,
plotpose) and a verbose-mode AttributeError in IBVS_e.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
mypy now reports no errors across the package.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Closes #152

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

codacy-production Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 5 high

Alerts:
⚠ 5 issues (≤ 0 issues of at least minor severity)

Results:
5 new issues

Category Results
ErrorProne 5 high

View in Codacy

🟢 Metrics -2 complexity · -2 duplication

Metric Results
Complexity -2
Duplication -2

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 changed the title feat: add py.typed marker and make the package pass mypy fix: add py.typed marker and make the package pass mypy Nov 18, 2026
petercorke and others added 3 commits November 19, 2026 08:39
Remove imports left unused by the typing changes, replace the asserts
added for mypy with explicit errors, import Any explicitly in ImageCore
and drop two unused locals in VisualServo.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@petercorke
petercorke merged commit 49f4606 into main Nov 19, 2026
32 of 33 checks passed
@petercorke
petercorke deleted the feat/py-typed branch November 19, 2026 00:13
@github-actions github-actions Bot mentioned this pull request Nov 18, 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.

Add a py.typed marker, so type checkers use this package's annotations

1 participant