Commit 8dd0e41
Address PR #401 R5 review (1 P2 transactional set_params)
R5 verdict was "Looks good" with one P2 code-quality regression
flagged. The previous round's `test_set_params_partial_mutation_recoverable`
documented inconsistent intermediate state as expected behavior:
on a mutex violation, `set_params()` mutated `self` before
validation, so a failed call left both `by_path` and
`paths_of_interest` populated. `fit()` did not re-check the mutex
and `_enumerate_treatment_paths()` silently preferred
`paths_of_interest` when both were set, so subsequent fits ran
with stale selector state unless the caller manually repaired the
object.
Fix: make `set_params()` transactional. Snapshot the pre-call
values for the keys being set, attempt mutation + validation, and
roll back to the snapshot on any exception before re-raising. This
mirrors sklearn-style atomic semantics. The validation block was
extracted into a private `_validate_invariants()` helper so
__init__ and set_params can share the rules without code
duplication risking drift.
Replaces `test_set_params_partial_mutation_recoverable` (which
asserted the buggy partial-mutation behavior) with
`test_set_params_failed_validation_is_transactional`, asserting
that:
1. After a failed `set_params()`, `get_params()` returns
bit-identical to the pre-call snapshot.
2. Subsequent valid `set_params()` succeeds against the rolled-
back state.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 053d2c2 commit 8dd0e41
2 files changed
Lines changed: 38 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
779 | 779 | | |
780 | 780 | | |
781 | 781 | | |
782 | | - | |
783 | | - | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
784 | 787 | | |
785 | | - | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
786 | 791 | | |
787 | 792 | | |
788 | | - | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
789 | 803 | | |
| 804 | + | |
| 805 | + | |
790 | 806 | | |
791 | 807 | | |
792 | 808 | | |
| |||
834 | 850 | | |
835 | 851 | | |
836 | 852 | | |
837 | | - | |
838 | 853 | | |
839 | 854 | | |
840 | 855 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8519 | 8519 | | |
8520 | 8520 | | |
8521 | 8521 | | |
8522 | | - | |
8523 | | - | |
| 8522 | + | |
| 8523 | + | |
| 8524 | + | |
| 8525 | + | |
| 8526 | + | |
8524 | 8527 | | |
8525 | | - | |
| 8528 | + | |
| 8529 | + | |
| 8530 | + | |
8526 | 8531 | | |
8527 | 8532 | | |
8528 | | - | |
8529 | | - | |
8530 | | - | |
| 8533 | + | |
| 8534 | + | |
| 8535 | + | |
| 8536 | + | |
| 8537 | + | |
| 8538 | + | |
| 8539 | + | |
| 8540 | + | |
8531 | 8541 | | |
8532 | | - | |
8533 | | - | |
| 8542 | + | |
| 8543 | + | |
8534 | 8544 | | |
8535 | 8545 | | |
8536 | 8546 | | |
| |||
0 commit comments