Repository navigation
Commit 65da216
committed
fix: Keep a FLOAT range element's spelling built from Python
`StepParameterSpace(taskParameterDefinitions={"F": {"type": "FLOAT", "range":
["1.50"]}})` rendered the task parameter value `1.5`, while the same element
decoded from a template rendered `1.50`. Review on #349 found it; measured, 5 of
6 elements disagreed between the two routes: '1.50'->1.5, '1e3'->1000.0,
'5.'->5.0, '.5'->0.5, '02.50'->2.5.
`task_param_def_from_dict` read every element through `v.str()` and re-emitted
the float variant as a JSON *number*. `Float64` reads a JSON number as a bare
value and a JSON string as a preserved spelling, so the number form threw the
decimal places away -- the thing openjd-rs#354 added `Float64` to carry.
The template makes this distinction with the `<float> | <floatstring>` union, so
the binding now makes it the same way: an element that arrives as a Python `str`
is forwarded as a JSON string, anything else keeps the numeric path. `v.str()`
collapsed the two, which is why the fix is a branch rather than a cast.
Deliberately not widened:
- A Python `float` must not acquire a spelling from `str()`. Measured, both
routes already agree on 1.5, 1000.0 and 0.5, and forwarding '1000.0' as
text would have been a new divergence in the other direction.
- An unparseable element still fails, in `Float64`'s deserializer rather than
here, exactly as it did when this re-emitted a number.
- `FloatTaskParameter.range` stays `list[float]`. It is the numeric
introspection view, so '2.50' still reports 2.5 there while rendering 2.50.
Two of them can compare equal by `.range` and render differently; the spec
now says so rather than the API changing shape.
- A redundant leading zero is still not stripped here. That is a `create_job`
normalization (openjd-model `create_job/ranges.rs`), not part of reading a
resolved value, and constructing the Rust `TaskParameter` directly behaves
the same way -- `Float64`'s deserializer trims whitespace and unsigns zero
but does not strip. So '02.50' given straight to the resolved type keeps its
zero. Pinned by name.
`TestFloatRangeSpellingIsPreserved` covers it: 10 string spellings, 3 float
negative controls, agreement with the template path, the leading-zero
divergence, and the rejection path. Mutation-checked by flipping the new branch
back to the numeric path, which fails 10 of the 16. The two survivors are
labelled in the test as not pinning the fix: '2.5' renders the same either way,
and ' 2.50 ' already took the string path because Rust's f64 parse rejects the
spaces.
Separately measured against openjd-rs#354 itself: all 26 input/expected pairs
from that PR's own assertions render identically through both this repo's
implementations, v0 and v1 -- including '-0.0'->0.0, '0e5', '-0.0E+2'->0.0E+2,
'1e-400', a 403-character 0.000...1, '5.' and '.5'.
Verified: 5567 passed, 24 skipped, 3 xfailed with the 94% coverage gate
enforced; cargo clippy --all-targets -D warnings, cargo fmt --check, cargo test,
ruff, black and mypy all clean.
Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>1 parent bfa28bc commit 65da216
3 files changed
Lines changed: 126 additions & 3 deletions
File tree
- rust-bindings/src/model
- specs
- test/openjd/model_v1
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
899 | 899 | | |
900 | 900 | | |
901 | 901 | | |
902 | | - | |
903 | | - | |
904 | | - | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
905 | 911 | | |
906 | 912 | | |
907 | 913 | | |
908 | 914 | | |
909 | 915 | | |
910 | 916 | | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
911 | 921 | | |
912 | 922 | | |
913 | 923 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
718 | 718 | | |
719 | 719 | | |
720 | 720 | | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
721 | 739 | | |
722 | 740 | | |
723 | 741 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
563 | 563 | | |
564 | 564 | | |
565 | 565 | | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
566 | 661 | | |
567 | 662 | | |
568 | 663 | | |
| |||
0 commit comments