Skip to content

fix: __version__ guard catches everything and leaves it unset on failure - #206

Open
petercorke wants to merge 1 commit into
rai-opensource:masterfrom
petercorke:fix/version-guard
Open

fix: __version__ guard catches everything and leaves it unset on failure#206
petercorke wants to merge 1 commit into
rai-opensource:masterfrom
petercorke:fix/version-guard

Conversation

@petercorke

Copy link
Copy Markdown
Collaborator

Summary

spatialmath/__init__.py's __version__ lookup used a bare except: pass, which has two problems:

  • Catches every exception during the importlib.metadata.version() call, not just the "package isn't installed" case (PackageNotFoundError) -- masking anything else that might go wrong there.
  • On failure, __version__ never gets set at all -- spatialmath.__version__ raises AttributeError rather than giving something to print, in e.g. a source checkout without an installed/editable distribution.

Narrowed the except to PackageNotFoundError and added an explicit "unknown" fallback so the attribute always exists.

Test plan

  • Normal path: import spatialmath; spatialmath.__version__ still resolves to the installed version (1.1.16 locally)
  • Failure path: monkeypatched importlib.metadata.version to raise PackageNotFoundError and confirmed __version__ falls back to "unknown" instead of being unset
  • New tests/test_version.py: asserts it's a non-empty string and matches pyproject.toml's version

Bare except: pass means any exception during the importlib.metadata
lookup gets silently swallowed (not just PackageNotFoundError for
"not installed"), and __version__ never gets set at all in that case --
spatialmath.__version__ raises AttributeError instead of giving
something to print. Narrow the except to PackageNotFoundError and
fall back to an explicit "unknown" so the attribute always exists.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
spatialmath/__init__.py 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

2 participants