fix: bring 3 mixins in line with the TYPE_CHECKING _ImageBase pattern - #29
Merged
Conversation
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).
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
ImageBlobsMixinandImageRegionFeaturesMixinwere missing the_ImageBaseProtocol entirely (plainobjectbase) that every other mixin uses for type-checker attribute info (self._A,self.colororder, etc.).ImagePointFeaturesMixinhad the opposite problem: imported and inherited_ImageBaseunconditionally, putting aProtocolclass into the real runtime MRO instead of type-check-time only.class XMixin(_ImageBase if TYPE_CHECKING else object)pattern. Zero runtime behavior change —_ImageBaseis a pure Protocol (all...stubs), confirmed via its own docstring and by checking no other code inImagePointFeatures.pyreferenced it outside the import/class declaration.tech-debt.md: a high-priority note thatmypyisn'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 AprilNOTESaudit); and a correction of my own initial hypothesis after checking the real data (the currentattr-definederrors are not from_ImageBasegaps — they're dominated by an unrelatedmachinevisiontoolbox/base/__init__.pywildcard-re-export resolution issue).Test plan
cls.__bases__is(object,)for all three mixins now, matching every other mixin