Repository navigation
Commit d0adcdf
authored
fix: __version__ guard catches everything and leaves it unset on failure (#206)
## 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
- [x] Normal path: `import spatialmath; spatialmath.__version__` still
resolves to the installed version (`1.1.16` locally)
- [x] Failure path: monkeypatched `importlib.metadata.version` to raise
`PackageNotFoundError` and confirmed `__version__` falls back to
`"unknown"` instead of being unset
- [x] New `tests/test_version.py`: asserts it's a non-empty string and
matches `pyproject.toml`'s `version`1 parent a016ffb commit d0adcdf
2 files changed
Lines changed: 27 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
0 commit comments