Commit 2650196
Refactor: Align Holdout implementation with Swift SDK
This commit refactors the holdout implementation to use proper entity
classes aligned with the Swift SDK architecture, improving type safety
and consistency across the codebase.
## Changes Made
### 1. entities.py
- Added Holdout entity class with proper type safety
- Implemented Holdout.Status constants matching Swift enum
- Added is_activated property (matches Swift's isActivated)
- Added get_audience_conditions_or_ids() method for consistent audience handling
### 2. project_config.py
- Converted holdout storage from dicts to Holdout entities
- Changed global_holdouts from dict to list (matching Swift SDK)
- Convert holdout variations to Variation entities during initialization
- Updated get_holdouts_for_flag() to return list[entities.Holdout]
- Updated get_holdout() to return Optional[entities.Holdout]
### 3. decision_service.py
- Updated get_variation_for_holdout() to accept Holdout entities
- Use is_activated property instead of dict status check
- Use get_audience_conditions_or_ids() for audience evaluation
- CRITICAL FIX: Return holdout as experiment field in Decision (was None)
- Removed HoldoutDict import, now uses entities.Holdout
### 4. bucketer.py
- Unified handling of Experiment and Holdout entities
- Removed dict-based branching for holdouts
- Use entity properties directly (key, id, trafficAllocation)
- Simplified variation lookup (now consistent for all entity types)
## Benefits
- **Type Safety**: Holdouts are now proper entity classes, not plain dicts
- **Consistency**: Holdouts work exactly like Experiments throughout codebase
- **Swift Alignment**: Python SDK matches Swift SDK's holdout architecture
- **Bug Fix**: Decision.experiment now returns Holdout entity (enables metadata access)
- **Maintainability**: Unified code paths reduce complexity
## Alignment with Swift SDK
This implementation now matches Swift SDK's approach where:
- Holdout is a proper struct/class conforming to ExperimentCore
- isActivated is a computed property
- Variations are proper Variation entities
- Decision returns the holdout as the experiment field
- Global holdouts stored as arrays/lists
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>1 parent 53421a6 commit 2650196
File tree
4 files changed
+170
-98
lines changed- optimizely
4 files changed
+170
-98
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
136 | 132 | | |
137 | 133 | | |
138 | 134 | | |
| |||
141 | 137 | | |
142 | 138 | | |
143 | 139 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
151 | 144 | | |
152 | 145 | | |
153 | 146 | | |
| |||
176 | 169 | | |
177 | 170 | | |
178 | 171 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
194 | 185 | | |
195 | 186 | | |
196 | 187 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
| |||
719 | 718 | | |
720 | 719 | | |
721 | 720 | | |
722 | | - | |
| 721 | + | |
723 | 722 | | |
724 | 723 | | |
725 | 724 | | |
| |||
748 | 747 | | |
749 | 748 | | |
750 | 749 | | |
751 | | - | |
| 750 | + | |
752 | 751 | | |
753 | 752 | | |
754 | 753 | | |
755 | 754 | | |
756 | 755 | | |
757 | 756 | | |
| 757 | + | |
| 758 | + | |
758 | 759 | | |
759 | | - | |
| 760 | + | |
760 | 761 | | |
761 | 762 | | |
762 | 763 | | |
| |||
769 | 770 | | |
770 | 771 | | |
771 | 772 | | |
772 | | - | |
773 | | - | |
774 | | - | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
775 | 777 | | |
776 | 778 | | |
777 | 779 | | |
| |||
783 | 785 | | |
784 | 786 | | |
785 | 787 | | |
786 | | - | |
787 | | - | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
788 | 791 | | |
789 | 792 | | |
790 | 793 | | |
791 | 794 | | |
792 | | - | |
| 795 | + | |
793 | 796 | | |
794 | 797 | | |
795 | 798 | | |
| |||
798 | 801 | | |
799 | 802 | | |
800 | 803 | | |
801 | | - | |
| 804 | + | |
802 | 805 | | |
803 | 806 | | |
804 | 807 | | |
| |||
810 | 813 | | |
811 | 814 | | |
812 | 815 | | |
813 | | - | |
| 816 | + | |
814 | 817 | | |
815 | 818 | | |
816 | 819 | | |
817 | 820 | | |
818 | | - | |
819 | | - | |
820 | 821 | | |
821 | | - | |
822 | | - | |
| 822 | + | |
| 823 | + | |
823 | 824 | | |
824 | 825 | | |
825 | 826 | | |
826 | 827 | | |
827 | | - | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
828 | 831 | | |
829 | | - | |
| 832 | + | |
830 | 833 | | |
831 | 834 | | |
832 | 835 | | |
| |||
837 | 840 | | |
838 | 841 | | |
839 | 842 | | |
840 | | - | |
| 843 | + | |
841 | 844 | | |
842 | 845 | | |
843 | 846 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
0 commit comments