Repository navigation
Commit 9ee7e8b
authored
fix: Twist3 * SpatialVector raised ValueError instead of dispatching (#210)
## Summary
- `Twist3.__mul__` raised a hard `ValueError` for any right operand it
didn't directly recognize (`Twist3`, `SE3`, scalar), instead of
returning `NotImplemented`. That meant Python never fell back to
`right.__rmul__(left)`, so `Twist3 * SpatialVelocity` /
`SpatialAcceleration` / `SpatialForce` / `SpatialMomentum` all failed
unconditionally -- even though `SpatialVector.__rmul__` explicitly
documents supporting `Twist3` alongside `SE3` (`isinstance(left, (SE3,
Twist3))`).
- Found while independently verifying #207
(`SpatialForce`/`SpatialMomentum` coadjoint fix): that PR's `Twist3`
code path (`SpatialForce.__rmul__`'s own override) is mathematically
correct but was untestable through normal `*` syntax because of this bug
-- it only worked via `SE3 *`.
- Fix: return `NotImplemented` for unrecognized right operands instead
of raising. Genuinely unsupported types (e.g. `Twist3(...) * "hello"`)
still fail, now with Python's standard `TypeError` rather than a custom
`ValueError`.
- Updates `Twist3.__mul__`'s own docstring table, which didn't mention
`SpatialVector` as a supported right operand at all.
- Fills in the `tests/test_spatialvector.py::test_products` stub
(previously just `pass`, with a comment literally noting "twist x v,
twist x a, twist x F" as untested) -- checks `Twist3 * X` agrees with
the equivalent `SE3 * X` for all four `SpatialVector` subclasses.
## Test plan
- [x] New test fails on unfixed code: `ValueError: twist *, incorrect
right operand`
- [x] Passes after the fix, for all of
`SpatialVelocity`/`SpatialAcceleration`/`SpatialForce`/`SpatialMomentum`
- [x] Confirmed genuinely unsupported types still fail, now with
`TypeError` (Python's standard) instead of the old custom `ValueError`
- [x] Grepped `tests/` for anything asserting the old `ValueError` --
nothing depends on it
- [x] `pytest tests/` -- full suite, 342 passed, no regressions1 parent 824a459 commit 9ee7e8b
2 files changed
Lines changed: 27 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1107 | 1107 | | |
1108 | 1108 | | |
1109 | 1109 | | |
| 1110 | + | |
1110 | 1111 | | |
1111 | 1112 | | |
1112 | 1113 | | |
1113 | 1114 | | |
1114 | 1115 | | |
1115 | 1116 | | |
1116 | 1117 | | |
1117 | | - | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
1118 | 1122 | | |
1119 | 1123 | | |
1120 | 1124 | | |
| |||
1147 | 1151 | | |
1148 | 1152 | | |
1149 | 1153 | | |
1150 | | - | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
1151 | 1159 | | |
1152 | 1160 | | |
1153 | 1161 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | | - | |
229 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
230 | 245 | | |
231 | 246 | | |
232 | 247 | | |
| |||
0 commit comments