Skip to content

Commit f7b71e7

Browse files
committed
Implement comment
1 parent 35f0741 commit f7b71e7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

optimizely/bucketer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# limitations under the License.
1313

1414
from __future__ import annotations
15-
from typing import Optional, TYPE_CHECKING
15+
from typing import Optional, TYPE_CHECKING, cast
1616
import math
1717
from sys import version_info
1818

@@ -29,7 +29,7 @@
2929
# prevent circular dependenacy by skipping import at runtime
3030
from .project_config import ProjectConfig
3131
from .entities import Experiment, Variation, Holdout
32-
from .helpers.types import TrafficAllocation, VariationDict
32+
from .helpers.types import TrafficAllocation
3333

3434

3535
MAX_TRAFFIC_VALUE: Final = 10000
@@ -105,7 +105,7 @@ def find_bucket(
105105
def bucket(
106106
self, project_config: ProjectConfig,
107107
experiment: Experiment | Holdout, user_id: str, bucketing_id: str
108-
) -> tuple[Optional[Variation | VariationDict], list[str]]:
108+
) -> tuple[Variation | None, list[str]]:
109109
""" For a given experiment and bucketing ID determines variation to be shown to user.
110110
111111
Args:
@@ -137,7 +137,8 @@ def bucket(
137137
variation_id, decide_reasons = self.bucket_to_entity_id(project_config, experiment, user_id, bucketing_id)
138138
if variation_id:
139139
variation = project_config.get_variation_from_id_by_experiment_id(experiment_id, variation_id)
140-
return variation, decide_reasons
140+
# Cast is safe here because experiments always use Variation entities, not VariationDict
141+
return cast(Optional[Variation], variation), decide_reasons
141142

142143
# No variation found - log message for empty traffic range
143144
message = 'Bucketed into an empty traffic range. Returning nil.'

0 commit comments

Comments
 (0)