Commit 96d9562
authored
fix: check_units result-callable receives units, not dimensions (#110)
The @check_units(result=callable) form passed each argument's *dimension*
to the result callable, but the returned value is validated by unit via
_check_unit/has_same_unit. has_same_unit calls get_unit() on the callable's
output; a Dimension collapses to Unit("1") there, so the comparison always
failed — even the documented example raised a spurious UnitMismatchError
("expected unit m^2 but got unit m^2").
Feed get_unit(a) instead so the callable produces a Unit, matching the
unit-based validation (check_dims correctly uses dimensions; assign_units
already uses units). Adds regression tests for the pass and mismatch paths.
Co-authored-by: Chaoming Wang <wcm.brainsim@gmail.com>1 parent a8f8c0f commit 96d9562
2 files changed
Lines changed: 25 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
488 | 488 | | |
489 | 489 | | |
490 | 490 | | |
491 | | - | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
492 | 495 | | |
493 | 496 | | |
494 | 497 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
269 | 290 | | |
270 | 291 | | |
271 | 292 | | |
| |||
0 commit comments