fix: replace 6 bare except: clauses with specific exception types - #31
Merged
Conversation
Confirmed pre-existing (git stash reproduces identically on unmodified main) and unrelated to the except-type narrowing in this branch -- found only because verifying the narrowed exception type required actually exercising gridify().
Bare except: swallows everything including KeyboardInterrupt and SystemExit, and hides the real failure mode from readers. Narrowed each to what the guarded code can actually raise: - BundleAdjust.py:15 -- `import pgraph` fallback -> ImportError - ImagePointFeatures.py:283 -- `nw, nh = nbins` unpack (scalar nbins is a valid, intentional fallback path, not an error) -> TypeError, ValueError - Camera.py:830 -- `artist.remove()` in clf(), arbitrary matplotlib Artist -> Exception (can't narrow further without knowing every Artist subclass's failure mode) - Camera.py:1865 -- arithmetic on possibly-unset imagesize/rho in fov() -> TypeError, AttributeError - ImageProcessing.py:1149 -- argcheck.getvector(image2, 3) -> Exception - __init__.py:191 -- importlib.metadata.version() lookup -> importlib.metadata.PackageNotFoundError Verified each guarded path still gets caught correctly: fov() called before imagesize/rho set still raises the intended ValueError; choose() with an invalid image2 still raises the intended ValueError. Full suite: 816 passed, 15 skipped, no regressions.
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.
# Conflicts: # tech-debt.md
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
Bare
except:swallows everything includingKeyboardInterrupt/SystemExitand hides the real failure mode. Narrowed all 6 in the codebase (confirmed via fresh grep — no more remain) to what the guarded code can actually raise:BundleAdjust.py:15import pgraphfallbackImportErrorImagePointFeatures.py:283nw, nh = nbinsunpack (scalarnbinsis a valid fallback path)TypeError, ValueErrorCamera.py:830artist.remove()inclf(), arbitrary matplotlibArtistExceptionCamera.py:1865imagesize/rhoinfov()TypeError, AttributeErrorImageProcessing.py:1149argcheck.getvector(image2, 3)Exception__init__.py:191importlib.metadata.version()lookupimportlib.metadata.PackageNotFoundErrorAlso logs a real bug found while verifying this (
gridify()'snw, nh = nbinspath) totech-debt.md— since fixed and merged separately in #30, not bundled here.Test plan
grep -rn "except:" src/machinevisiontoolbox/*.py— zero matchesfov()called beforeimagesize/rhoset still raises the intendedValueError;choose()with an invalidimage2still raises the intendedValueError