Skip to content

fix: bring 3 mixins in line with the TYPE_CHECKING _ImageBase pattern - #29

Merged
petercorke merged 3 commits into
mainfrom
fix/mixin-protocol-consistency
Jul 30, 2026
Merged

fix: bring 3 mixins in line with the TYPE_CHECKING _ImageBase pattern#29
petercorke merged 3 commits into
mainfrom
fix/mixin-protocol-consistency

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

  • ImageBlobsMixin and ImageRegionFeaturesMixin were missing the _ImageBase Protocol entirely (plain object base) that every other mixin uses for type-checker attribute info (self._A, self.colororder, etc.).
  • ImagePointFeaturesMixin had the opposite problem: imported and inherited _ImageBase unconditionally, putting a Protocol class into the real runtime MRO instead of type-check-time only.
  • Brought all three in line with the established class XMixin(_ImageBase if TYPE_CHECKING else object) pattern. Zero runtime behavior change — _ImageBase is a pure Protocol (all ... stubs), confirmed via its own docstring and by checking no other code in ImagePointFeatures.py referenced it outside the import/class declaration.
  • Also logs two things found while doing this, to tech-debt.md: a high-priority note that mypy isn't run anywhere (so a Protocol gap like this has zero automated signal), with a fresh full audit (524 errors/31 files, categorized, superseding the stale April NOTES audit); and a correction of my own initial hypothesis after checking the real data (the current attr-defined errors are not from _ImageBase gaps — they're dominated by an unrelated machinevisiontoolbox/base/__init__.py wildcard-re-export resolution issue).

Test plan

  • cls.__bases__ is (object,) for all three mixins now, matching every other mixin
  • Full suite: 816 passed, 15 skipped

pgraph-python is a declared pyproject.toml dependency but is entirely
absent from ci.yml's create-args -- BundleAdjust.py's only import of it
is wrapped in a bare except that silently falls back, so CI has been
exercising that code in "not installed" mode the whole time.

Also records the decision not to do the conda->pip migration now:
known non-technical origin (contributor's conda preference), and
today's new branch protection (required All tests passed + build,
strict mode) already contains the blast radius of a future incident
the way it hit multiple PRs at once today.
Prompted by fixing the _ImageBase Protocol gaps in this same branch:
if a mixin calls a cross-mixin self.attr not yet declared in
_image_typing.py, nothing catches it -- mypy isn't in pyproject.toml's
dev extra or any CI workflow. Same "hand-maintained shadow list, no
automated check" pattern as the docs sidebar and ci.yml create-args
issues found earlier today, just quieter (no visible failure mode at
all, vs. a missing page or a red build).

Ran mypy fresh (524 errors/31 files, superseding the stale April NOTES
audit) and categorized. Corrects an initial hypothesis: checked whether
attr-defined errors trace to _ImageBase gaps -- they don't, currently.
The two real dominant causes are machinevisiontoolbox/base/__init__.py's
unresolvable wildcard re-exports and cv2 dynamic dispatch, both
unrelated to the mixin-Protocol question that prompted the audit.
Every mixin in src/machinevisiontoolbox/ follows
class XMixin(_ImageBase if TYPE_CHECKING else object), with _ImageBase
imported inside an if TYPE_CHECKING: block -- _ImageBase is a pure
Protocol (all ... stubs, no implementation), so this is a zero-runtime-
behavior-change pattern used purely to give type checkers attribute
info without adding anything to the real MRO.

Three files didn't follow it:
- ImageBlobsMixin / ImageRegionFeaturesMixin: no _ImageBase at all
  (plain `object` base), so self._A/self.colororder/etc. accesses
  inside these two mixins had no type info.
- ImagePointFeaturesMixin: the opposite problem -- imported and
  inherited _ImageBase unconditionally, putting a Protocol class into
  the real runtime MRO. Verified this was always a no-op in practice
  (_image_typing.py's own docstring: "never instantiated, adds nothing
  to the MRO"; confirmed no other code in the file referenced
  _ImageBase outside the import and class declaration), so making it
  TYPE_CHECKING-only is a safe, behavior-preserving fix.

Verified: `cls.__bases__` is `(object,)` for all three mixins now
(matching every other mixin), full suite passes (816 passed, 15
skipped).
@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 a226fc4 into main Jul 30, 2026
18 checks passed
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