Skip to content

Commit d2e38fe

Browse files
committed
update string docs for_identifier*()
1 parent 8d5f821 commit d2e38fe

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

reddit_decider/__init__.py

+29-6
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,14 @@ def get_variant_for_identifier(
452452
) -> Optional[str]:
453453
"""Return a bucketing variant, if any, with auto-exposure for a given :code:`identifier`.
454454
455+
Note: If the experiment's :code:`bucket_val` (e.g. "user_id", "device_id", "canonical_url")
456+
does not match the :code:`identifier_type` param,
457+
the :code:`identifier` will be ignored and not used to bucket (:code:`{identifier_type: identifier}` is
458+
added to internal :code:`DeciderContext` instance, but doesn't act like a bucketing override).
459+
460+
If the :code:`bucket_val` field exists on the :code:`DeciderContext` instance,
461+
that field will be used to bucket, since it corresponds to the experiment's config.
462+
455463
Since calling :code:`get_variant_for_identifier()` will fire an exposure event, it
456464
is best to call it when you are sure the user will be exposed to the experiment.
457465
@@ -460,8 +468,11 @@ def get_variant_for_identifier(
460468
:param identifier: an arbitary string used to bucket the experiment by
461469
being set on :code:`DeciderContext`'s :code:`identifier_type` field.
462470
463-
:param identifier_type: Sets :code:`{identifier_type: identifier}` on DeciderContext and
464-
should match an experiment's :code:`bucket_val` to get a variant.
471+
:param identifier_type: Sets :code:`{identifier_type: identifier}` on :code:`DeciderContext`.
472+
The experiment's :code:`bucket_val` will be looked up in :code:`DeciderContext` and be used to bucket.
473+
If the experiment's :code:`bucket_val` field does not match :code:`identifier_type` param,
474+
:code:`identifier` will be ignored, and the field corresponding :code:`bucket_val` will be looked up
475+
from :code:`DeciderContext` for bucketing.
465476
466477
:param exposure_kwargs: Additional arguments that will be passed
467478
to :code:`events_logger` (keys must be part of v2 event schema,
@@ -508,6 +519,14 @@ def get_variant_for_identifier_without_expose(
508519
) -> Optional[str]:
509520
"""Return a bucketing variant, if any, without emitting exposure event for a given :code:`identifier`.
510521
522+
Note: If the experiment's :code:`bucket_val` (e.g. "user_id", "device_id", "canonical_url")
523+
does not match the :code:`identifier_type` param,
524+
the :code:`identifier` will be ignored and not used to bucket (:code:`{identifier_type: identifier}` is
525+
added to internal :code:`DeciderContext` instance, but doesn't act like a bucketing override).
526+
527+
If the :code:`bucket_val` field exists on the :code:`DeciderContext` instance,
528+
that field will be used to bucket, since it corresponds to the experiment's config.
529+
511530
The :code:`expose()` function is available to be manually called afterward to emit
512531
exposure event.
513532
@@ -522,8 +541,11 @@ def get_variant_for_identifier_without_expose(
522541
:param identifier: an arbitary string used to bucket the experiment by
523542
being set on :code:`DeciderContext`'s :code:`identifier_type` field.
524543
525-
:param identifier_type: Sets :code:`{identifier_type: identifier}` on DeciderContext and
526-
should match an experiment's :code:`bucket_val` to get a variant.
544+
:param identifier_type: Sets :code:`{identifier_type: identifier}` on :code:`DeciderContext`.
545+
The experiment's :code:`bucket_val` will be looked up in :code:`DeciderContext` and be used to bucket.
546+
If the experiment's :code:`bucket_val` field does not match :code:`identifier_type` param,
547+
:code:`identifier` will be ignored and the field corresponding :code:`bucket_val` will be looked up
548+
from :code:`DeciderContext` for bucketing.
527549
528550
:return: Variant name if a variant is assigned, None otherwise.
529551
"""
@@ -631,7 +653,8 @@ def get_all_variants_without_expose(self) -> List[Dict[str, Union[str, int]]]:
631653
def get_all_variants_for_identifier_without_expose(
632654
self, identifier: str, identifier_type: Literal["user_id", "device_id", "canonical_url"]
633655
) -> List[Dict[str, Union[str, int]]]:
634-
"""Return a list of experiment dicts for a given :code:`identifier` in this format:
656+
"""Return a list of experiment dicts for experiments having :code:`bucket_val` match
657+
:code:`identifier_type`, for a given :code:`identifier`, in this format:
635658
636659
.. code-block:: json
637660
@@ -658,7 +681,7 @@ def get_all_variants_for_identifier_without_expose(
658681
being set on :code:`DeciderContext`'s :code:`identifier_type` field.
659682
660683
:param identifier_type: Sets :code:`{identifier_type: identifier}` on DeciderContext and
661-
should match an experiment's :code:`bucket_val` to get a variant.
684+
buckets all experiment with matching :code:`bucket_val`.
662685
663686
:return: list of experiment dicts with non-:code:`None` variants.
664687
"""

0 commit comments

Comments
 (0)