Skip to content

Commit cc7c2ab

Browse files
committed
refactor: split PROPERTY_OPERATORS into composable sub-groups
Break the flat tuple into category-specific tuples (EQUALITY_OPERATORS, STRING_OPERATORS, etc.) that compose into PROPERTY_OPERATORS via concatenation. The semver dispatch code now references SEMVER_OPERATORS and SEMVER_COMPARISON_OPERATORS instead of repeating the full operator lists inline.
1 parent 046c90b commit cc7c2ab

File tree

1 file changed

+17
-42
lines changed

1 file changed

+17
-42
lines changed

posthog/feature_flags.py

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,27 @@
1919
NONE_VALUES_ALLOWED_OPERATORS = ["is_not"]
2020

2121
# All operators supported by match_property, grouped by category.
22-
PROPERTY_OPERATORS = (
23-
# Equality
24-
"exact",
25-
"is_not",
26-
"is_set",
27-
"is_not_set",
28-
# String matching
29-
"icontains",
30-
"not_icontains",
31-
"regex",
32-
"not_regex",
33-
# Numeric / string comparison
34-
"gt",
35-
"gte",
36-
"lt",
37-
"lte",
38-
# Date comparison
39-
"is_date_before",
40-
"is_date_after",
41-
# Semver comparison
22+
EQUALITY_OPERATORS = ("exact", "is_not", "is_set", "is_not_set")
23+
STRING_OPERATORS = ("icontains", "not_icontains", "regex", "not_regex")
24+
NUMERIC_OPERATORS = ("gt", "gte", "lt", "lte")
25+
DATE_OPERATORS = ("is_date_before", "is_date_after")
26+
SEMVER_COMPARISON_OPERATORS = (
4227
"semver_eq",
4328
"semver_neq",
4429
"semver_gt",
4530
"semver_gte",
4631
"semver_lt",
4732
"semver_lte",
48-
"semver_tilde",
49-
"semver_caret",
50-
"semver_wildcard",
33+
)
34+
SEMVER_RANGE_OPERATORS = ("semver_tilde", "semver_caret", "semver_wildcard")
35+
SEMVER_OPERATORS = SEMVER_COMPARISON_OPERATORS + SEMVER_RANGE_OPERATORS
36+
37+
PROPERTY_OPERATORS = (
38+
EQUALITY_OPERATORS
39+
+ STRING_OPERATORS
40+
+ NUMERIC_OPERATORS
41+
+ DATE_OPERATORS
42+
+ SEMVER_OPERATORS
5143
)
5244

5345

@@ -540,32 +532,15 @@ def compare(lhs, rhs, operator):
540532
"The date provided must be a string or date object"
541533
)
542534

543-
if operator in (
544-
"semver_eq",
545-
"semver_neq",
546-
"semver_gt",
547-
"semver_gte",
548-
"semver_lt",
549-
"semver_lte",
550-
"semver_tilde",
551-
"semver_caret",
552-
"semver_wildcard",
553-
):
535+
if operator in SEMVER_OPERATORS:
554536
try:
555537
override_parsed = parse_semver(override_value)
556538
except (ValueError, TypeError):
557539
raise InconclusiveMatchError(
558540
f"Person property value '{override_value}' is not a valid semver"
559541
)
560542

561-
if operator in (
562-
"semver_eq",
563-
"semver_neq",
564-
"semver_gt",
565-
"semver_gte",
566-
"semver_lt",
567-
"semver_lte",
568-
):
543+
if operator in SEMVER_COMPARISON_OPERATORS:
569544
try:
570545
flag_parsed = parse_semver(value)
571546
except (ValueError, TypeError):

0 commit comments

Comments
 (0)