Skip to content

Commit 4012ab6

Browse files
committed
docs: trim comments and docstrings to the essentials
Signed-off-by: wadii <wadii.zaim@flagsmith.com>
1 parent 2682781 commit 4012ab6

3 files changed

Lines changed: 22 additions & 44 deletions

File tree

‎openfeature_flagsmith/hooks.py‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,16 @@
1919

2020

2121
def _is_split_reason(reason: typing.Union[str, Reason, None]) -> bool:
22-
# The Flagsmith engine annotates reasons with k=v metadata
23-
# ("SPLIT; weight=30"); compare the leading token so the gate keeps
24-
# working once the API exposes annotated reasons.
22+
# The engine annotates reasons ("SPLIT; weight=30"); compare the
23+
# leading token.
2524
if reason is None:
2625
return False
2726
return str(reason).split(";", 1)[0].strip() == Reason.SPLIT.value
2827

2928

3029
class FlagsmithExposureHook(Hook):
3130
"""
32-
Records a Flagsmith exposure as a side effect of a flag evaluation, so one
33-
call both resolves the flag and marks the identity as exposed to its
34-
variant — the OpenFeature equivalent of Flagsmith's ``get_experiment_flag``::
31+
Records a Flagsmith exposure as a side effect of a flag evaluation::
3532
3633
hook = FlagsmithExposureHook(provider)
3734
client.get_string_details(
@@ -43,13 +40,8 @@ class FlagsmithExposureHook(Hook):
4340
4441
Attaching the hook at a call site is the experiment declaration:
4542
evaluations without it never record exposures. Exposures only fire for
46-
multivariate flags resolved with reason ``SPLIT`` (a percentage-split
47-
assignment: enabled, identified, not offline; engine-annotated reason
48-
strings like ``"SPLIT; weight=30"`` also match), and are deduped per
49-
identity/flag/variant in a bounded, thread-safe LRU for the hook
50-
instance's lifetime.
51-
52-
Tracking is an experimental OpenFeature capability (spec section 6).
43+
flags resolved with a variant and reason ``SPLIT``, deduped per
44+
identity/flag/variant in a bounded, thread-safe LRU.
5345
"""
5446

5547
def __init__(
@@ -68,8 +60,7 @@ def after(
6860
details: FlagEvaluationDetails,
6961
hints: HookHints,
7062
) -> None:
71-
# Fully error-contained: an uncaught after-hook error flips the
72-
# evaluation itself to ERROR in the OpenFeature SDK.
63+
# An uncaught after-hook error would flip the evaluation to ERROR.
7364
try:
7465
variant = details.variant
7566
if not isinstance(variant, str):
@@ -82,7 +73,7 @@ def after(
8273
)
8374
return
8475
targeting_key = hook_context.evaluation_context.targeting_key
85-
# json.dumps of the list avoids delimiter-collision false dedupes.
76+
# json.dumps avoids delimiter collisions in the key.
8677
dedupe_key = json.dumps([targeting_key, details.flag_key, variant])
8778
with self._lock:
8879
if dedupe_key in self._seen:

‎openfeature_flagsmith/provider.py‎

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ def track(
5656
Route OpenFeature tracking events to Flagsmith.
5757
5858
``EXPOSURE_TRACKING_EVENT`` records a flag/variant exposure; any other
59-
name becomes a plain Flagsmith event with ``details.value`` first-class.
60-
No-ops unless the client was initialized with ``enable_events``. Never
61-
raises (OpenFeature spec section 6): unexpected errors are logged.
59+
name becomes a plain Flagsmith event. No-ops unless the client was
60+
initialized with ``enable_events``. Never raises: errors are logged.
6261
"""
6362
try:
6463
self._track(tracking_event_name, evaluation_context, tracking_event_details)
@@ -75,9 +74,8 @@ def _track(
7574
evaluation_context: typing.Optional[EvaluationContext],
7675
tracking_event_details: typing.Optional[TrackingEventDetails],
7776
) -> None:
78-
# Private-attribute pragmatism: the SDK has no public events-enabled
79-
# signal yet. Checked up front so disabled events never trigger
80-
# network side effects (identity persistence, flag fetches).
77+
# The SDK has no public events-enabled signal; check first so
78+
# disabled events cause no network side effects.
8179
if getattr(self._client, "_event_processor", None) is None:
8280
logger.debug(
8381
'Flagsmith events are disabled; dropping tracking event "%s".',
@@ -124,8 +122,7 @@ def _track(
124122
metadata=attributes or None,
125123
)
126124
except ValueError:
127-
# Raised when events are disabled (racing the check above) or the
128-
# SDK rejects the event name.
125+
# Events disabled (racing the check above) or name rejected.
129126
logger.debug(
130127
'Flagsmith rejected tracking event "%s"; dropping it.',
131128
tracking_event_name,
@@ -171,10 +168,8 @@ def _track_exposure(
171168
)
172169
return
173170

174-
# Mirrors the SDK's get_experiment_flag guards, with the exposure
175-
# attributed to the OF context's targeting key rather than any
176-
# ambient identity. This resolution counts as a flag evaluation,
177-
# exactly like get_experiment_flag itself.
171+
# Mirrors the SDK's get_experiment_flag guards, attributed to the
172+
# context's targeting key rather than any ambient identity.
178173
try:
179174
flag = self._client.get_identity_flags(
180175
identifier=identifier,
@@ -320,7 +315,7 @@ def _build_details(
320315
return FlagResolutionDetails(
321316
value=value,
322317
reason=self._parse_reason(flag, evaluation_context),
323-
# DefaultFlag has no `variant` attribute; never use bare access.
318+
# DefaultFlag has no `variant` attribute.
324319
variant=getattr(flag, "variant", None),
325320
flag_metadata=self._build_flag_metadata(flag),
326321
)
@@ -332,15 +327,12 @@ def _parse_reason(
332327
return Reason.DEFAULT
333328
if not flag.enabled:
334329
return Reason.DISABLED
335-
# Offline documents may be arbitrarily old; the exposure hook treats
336-
# anything but SPLIT as not fresh enough to record.
330+
# Offline documents may be arbitrarily old.
337331
if getattr(self._client, "offline_mode", False):
338332
return Reason.STALE
339333
if evaluation_context.targeting_key:
340-
# Engine taxonomy: a variant means a multivariate percentage-split
341-
# assignment (SPLIT); TARGETING_MATCH is reserved for segment
342-
# matches, which the API can't distinguish from environment
343-
# defaults yet, so no-variant identity evaluations stay coarse.
334+
# A variant means a percentage-split assignment (SPLIT);
335+
# TARGETING_MATCH is reserved for segment matches.
344336
if getattr(flag, "variant", None) is not None:
345337
return Reason.SPLIT
346338
return Reason.TARGETING_MATCH
@@ -349,7 +341,7 @@ def _parse_reason(
349341
def _build_flag_metadata(
350342
self, flag: typing.Any
351343
) -> typing.Dict[str, typing.Union[bool, int, str]]:
352-
# Keys are byte-identical with the JS provider (vendor-council aligned).
344+
# Keys are byte-identical with the JS provider.
353345
metadata: typing.Dict[str, typing.Union[bool, int, str]] = {
354346
"enabled": flag.enabled
355347
}
@@ -369,8 +361,7 @@ def _extract_traits(
369361
if not evaluation_context or not evaluation_context.attributes:
370362
return None
371363
nested = evaluation_context.attributes.get("traits", {})
372-
# `traits` is unpacked below; the flat `transient` key is an
373-
# evaluation directive (see _is_transient), not a trait.
364+
# The flat `transient` key is an evaluation directive, not a trait.
374365
flat = {
375366
k: v
376367
for k, v in evaluation_context.attributes.items()

‎openfeature_flagsmith/tracking.py‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
"""
55
Reserved tracking-event name for recording flag/variant exposures.
66
7-
``client.track(EXPOSURE_TRACKING_EVENT, context, details)`` routes to
8-
Flagsmith's exposure tracking instead of a plain analytics event. This is the
9-
OpenFeature-facing name (identical across Flagsmith OpenFeature providers); on
10-
the wire the Flagsmith SDK emits the ``$flag_exposure`` system event.
11-
12-
Tracking is an experimental OpenFeature capability (spec section 6).
7+
OpenFeature-facing name, identical across Flagsmith providers; on the wire
8+
the SDK emits the ``$flag_exposure`` system event.
139
"""

0 commit comments

Comments
 (0)