Skip to content

Commit bad81fc

Browse files
committed
update string docs for_identifier*()
1 parent dc5102e commit bad81fc

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

reddit_decider/__init__.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,14 @@ def get_variant_for_identifier(
453453
) -> Optional[str]:
454454
"""Return a bucketing variant, if any, with auto-exposure for a given :code:`identifier`.
455455
456+
Note: If the experiment's :code:`bucket_val` (e.g. "user_id", "device_id", "canonical_url")
457+
does not match the :code:`identifier_type` param,
458+
the :code:`identifier` will be ignored and not used to bucket (:code:`{identifier_type: identifier}` is
459+
added to internal :code:`DeciderContext` instance, but doesn't act like a bucketing override).
460+
461+
If the :code:`bucket_val` field exists on the :code:`DeciderContext` instance,
462+
that field will be used to bucket, since it corresponds to the experiment's config.
463+
456464
Since calling :code:`get_variant_for_identifier()` will fire an exposure event, it
457465
is best to call it when you are sure the user will be exposed to the experiment.
458466
@@ -461,8 +469,11 @@ def get_variant_for_identifier(
461469
:param identifier: an arbitary string used to bucket the experiment by
462470
being set on :code:`DeciderContext`'s :code:`identifier_type` field.
463471
464-
:param identifier_type: Sets :code:`{identifier_type: identifier}` on DeciderContext and
465-
should match an experiment's :code:`bucket_val` to get a variant.
472+
:param identifier_type: Sets :code:`{identifier_type: identifier}` on :code:`DeciderContext`.
473+
The experiment's :code:`bucket_val` will be looked up in :code:`DeciderContext` and be used to bucket.
474+
If the experiment's :code:`bucket_val` field does not match :code:`identifier_type` param,
475+
:code:`identifier` will be ignored, and the field corresponding :code:`bucket_val` will be looked up
476+
from :code:`DeciderContext` for bucketing.
466477
467478
:param exposure_kwargs: Additional arguments that will be passed
468479
to :code:`events_logger` (keys must be part of v2 event schema,
@@ -509,6 +520,14 @@ def get_variant_for_identifier_without_expose(
509520
) -> Optional[str]:
510521
"""Return a bucketing variant, if any, without emitting exposure event for a given :code:`identifier`.
511522
523+
Note: If the experiment's :code:`bucket_val` (e.g. "user_id", "device_id", "canonical_url")
524+
does not match the :code:`identifier_type` param,
525+
the :code:`identifier` will be ignored and not used to bucket (:code:`{identifier_type: identifier}` is
526+
added to internal :code:`DeciderContext` instance, but doesn't act like a bucketing override).
527+
528+
If the :code:`bucket_val` field exists on the :code:`DeciderContext` instance,
529+
that field will be used to bucket, since it corresponds to the experiment's config.
530+
512531
The :code:`expose()` function is available to be manually called afterward to emit
513532
exposure event.
514533
@@ -523,8 +542,11 @@ def get_variant_for_identifier_without_expose(
523542
:param identifier: an arbitary string used to bucket the experiment by
524543
being set on :code:`DeciderContext`'s :code:`identifier_type` field.
525544
526-
:param identifier_type: Sets :code:`{identifier_type: identifier}` on DeciderContext and
527-
should match an experiment's :code:`bucket_val` to get a variant.
545+
:param identifier_type: Sets :code:`{identifier_type: identifier}` on :code:`DeciderContext`.
546+
The experiment's :code:`bucket_val` will be looked up in :code:`DeciderContext` and be used to bucket.
547+
If the experiment's :code:`bucket_val` field does not match :code:`identifier_type` param,
548+
:code:`identifier` will be ignored and the field corresponding :code:`bucket_val` will be looked up
549+
from :code:`DeciderContext` for bucketing.
528550
529551
:return: Variant name if a variant is assigned, None otherwise.
530552
"""
@@ -625,7 +647,8 @@ def _decision_to_dict(self, decision: Decision) -> Dict[str, Any]:
625647
def get_all_variants_for_identifier_without_expose(
626648
self, identifier: str, identifier_type: Literal["user_id", "device_id", "canonical_url"]
627649
) -> List[Dict[str, Union[str, int]]]:
628-
"""Return a list of experiment dicts for a given :code:`identifier` in this format:
650+
"""Return a list of experiment dicts for experiments having :code:`bucket_val` match
651+
:code:`identifier_type`, for a given :code:`identifier`, in this format:
629652
630653
.. code-block:: json
631654
@@ -652,7 +675,7 @@ def get_all_variants_for_identifier_without_expose(
652675
being set on :code:`DeciderContext`'s :code:`identifier_type` field.
653676
654677
:param identifier_type: Sets :code:`{identifier_type: identifier}` on DeciderContext and
655-
should match an experiment's :code:`bucket_val` to get a variant.
678+
buckets all experiment with matching :code:`bucket_val`.
656679
657680
:return: list of experiment dicts with non-:code:`None` variants.
658681
"""

0 commit comments

Comments
 (0)