Skip to content

Commit 6f9cd56

Browse files
committed
Fix mypy type errors in flag dependencies
- Add type validation for flag dependency expected values - Handle Optional[bool] returns from match_flag_property correctly - Use explicit variable assignments to satisfy mypy type checker This resolves type checking issues while maintaining functionality.
1 parent b90a7a9 commit 6f9cd56

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

posthog/feature_flags.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,13 @@ def match_flag_property(
441441

442442
if not dependency_id:
443443
return None
444+
445+
# Validate expected_value type
446+
if not isinstance(expected_value, (bool, str)):
447+
log.warning(
448+
f"Invalid value type for flag dependency: {type(expected_value)}. Expected bool or str."
449+
)
450+
return None
444451

445452
# Only exact operator is supported for flag dependencies
446453
if operator != "exact":
@@ -578,15 +585,16 @@ def is_condition_match(
578585
prop, properties, cohort_properties, dependency_graph, id_to_key
579586
)
580587
elif property_type == "flag":
581-
matches = match_flag_property(prop, dependency_graph, id_to_key)
582-
if matches is None:
588+
flag_matches = match_flag_property(prop, dependency_graph, id_to_key)
589+
if flag_matches is None:
583590
# Dependency not available, skip this condition
584591
log.warning(
585592
"Flag dependency on '%s' not available for flag '%s'. Skipping condition.",
586593
prop.get("key", "unknown"),
587594
feature_flag.get("key", "unknown"),
588595
)
589596
continue
597+
matches = flag_matches
590598
else:
591599
matches = match_property(prop, properties)
592600
if not matches:
@@ -818,14 +826,15 @@ def match_property_group(
818826
id_to_key,
819827
)
820828
elif prop.get("type") == "flag":
821-
matches = match_flag_property(prop, dependency_graph, id_to_key)
822-
if matches is None:
829+
flag_matches = match_flag_property(prop, dependency_graph, id_to_key)
830+
if flag_matches is None:
823831
# Dependency not available, skip this condition
824832
log.warning(
825833
"Flag dependency on '%s' not available. Skipping condition.",
826834
prop.get("key", "unknown"),
827835
)
828836
continue
837+
matches = flag_matches
829838
else:
830839
matches = match_property(prop, property_values)
831840

0 commit comments

Comments
 (0)