@@ -83,6 +83,7 @@ def get_identity_state(passed) -> tuple[str, bool]:
83
83
84
84
85
85
def add_context_tags (properties ):
86
+ properties = properties or {}
86
87
current_context = _get_current_context ()
87
88
if current_context :
88
89
context_tags = current_context .collect_tags ()
@@ -327,14 +328,17 @@ def get_feature_flags_and_payloads(
327
328
def get_flags_decision (
328
329
self ,
329
330
distinct_id : Optional [ID_TYPES ] = None ,
330
- groups : Optional [dict ] = {} ,
331
+ groups : Optional [dict ] = None ,
331
332
person_properties = None ,
332
333
group_properties = None ,
333
334
disable_geoip = None ,
334
335
) -> FlagsResponse :
335
336
"""
336
337
Get feature flags decision, using either flags() or decide() API based on rollout.
337
338
"""
339
+ groups = groups or {}
340
+ person_properties = person_properties or {}
341
+ group_properties = group_properties or {}
338
342
339
343
if distinct_id is None :
340
344
distinct_id = get_context_distinct_id ()
@@ -376,6 +380,7 @@ def capture(
376
380
properties = {** (properties or {}), ** system_context ()}
377
381
378
382
properties = add_context_tags (properties )
383
+ assert properties is not None # Type hint for mypy
379
384
380
385
(distinct_id , personless ) = get_identity_state (distinct_id )
381
386
@@ -391,7 +396,7 @@ def capture(
391
396
}
392
397
393
398
if groups :
394
- msg [ " properties" ] ["$groups" ] = groups
399
+ properties ["$groups" ] = groups
395
400
396
401
extra_properties : dict [str , Any ] = {}
397
402
feature_variants : Optional [dict [str , Union [bool , str ]]] = {}
@@ -426,7 +431,8 @@ def capture(
426
431
extra_properties ["$active_feature_flags" ] = active_feature_flags
427
432
428
433
if extra_properties :
429
- msg ["properties" ] = {** extra_properties , ** msg ["properties" ]}
434
+ properties = {** extra_properties , ** properties }
435
+ msg ["properties" ] = properties
430
436
431
437
return self ._enqueue (msg , disable_geoip )
432
438
@@ -819,11 +825,15 @@ def _compute_flag_locally(
819
825
feature_flag ,
820
826
distinct_id ,
821
827
* ,
822
- groups = {} ,
823
- person_properties = {} ,
824
- group_properties = {} ,
828
+ groups = None ,
829
+ person_properties = None ,
830
+ group_properties = None ,
825
831
warn_on_unknown_groups = True ,
826
832
) -> FlagValue :
833
+ groups = groups or {}
834
+ person_properties = person_properties or {}
835
+ group_properties = group_properties or {}
836
+
827
837
if feature_flag .get ("ensure_experience_continuity" , False ):
828
838
raise InconclusiveMatchError ("Flag has experience continuity enabled" )
829
839
@@ -869,9 +879,9 @@ def feature_enabled(
869
879
key ,
870
880
distinct_id ,
871
881
* ,
872
- groups = {} ,
873
- person_properties = {} ,
874
- group_properties = {} ,
882
+ groups = None ,
883
+ person_properties = None ,
884
+ group_properties = None ,
875
885
only_evaluate_locally = False ,
876
886
send_feature_flag_events = True ,
877
887
disable_geoip = None ,
@@ -897,9 +907,9 @@ def _get_feature_flag_result(
897
907
distinct_id : ID_TYPES ,
898
908
* ,
899
909
override_match_value : Optional [FlagValue ] = None ,
900
- groups : Dict [str , str ] = {} ,
901
- person_properties = {} ,
902
- group_properties = {} ,
910
+ groups : Optional [ Dict [str , str ]] = None ,
911
+ person_properties = None ,
912
+ group_properties = None ,
903
913
only_evaluate_locally = False ,
904
914
send_feature_flag_events = True ,
905
915
disable_geoip = None ,
@@ -909,9 +919,16 @@ def _get_feature_flag_result(
909
919
910
920
person_properties , group_properties = (
911
921
self ._add_local_person_and_group_properties (
912
- distinct_id , groups , person_properties , group_properties
922
+ distinct_id ,
923
+ groups or {},
924
+ person_properties or {},
925
+ group_properties or {},
913
926
)
914
927
)
928
+ # Ensure non-None values for type checking
929
+ groups = groups or {}
930
+ person_properties = person_properties or {}
931
+ group_properties = group_properties or {}
915
932
916
933
flag_result = None
917
934
flag_details = None
@@ -995,9 +1012,9 @@ def get_feature_flag_result(
995
1012
key ,
996
1013
distinct_id ,
997
1014
* ,
998
- groups = {} ,
999
- person_properties = {} ,
1000
- group_properties = {} ,
1015
+ groups = None ,
1016
+ person_properties = None ,
1017
+ group_properties = None ,
1001
1018
only_evaluate_locally = False ,
1002
1019
send_feature_flag_events = True ,
1003
1020
disable_geoip = None ,
@@ -1024,9 +1041,9 @@ def get_feature_flag(
1024
1041
key ,
1025
1042
distinct_id ,
1026
1043
* ,
1027
- groups = {} ,
1028
- person_properties = {} ,
1029
- group_properties = {} ,
1044
+ groups = None ,
1045
+ person_properties = None ,
1046
+ group_properties = None ,
1030
1047
only_evaluate_locally = False ,
1031
1048
send_feature_flag_events = True ,
1032
1049
disable_geoip = None ,
@@ -1094,9 +1111,9 @@ def get_feature_flag_payload(
1094
1111
distinct_id ,
1095
1112
* ,
1096
1113
match_value : Optional [FlagValue ] = None ,
1097
- groups = {} ,
1098
- person_properties = {} ,
1099
- group_properties = {} ,
1114
+ groups = None ,
1115
+ person_properties = None ,
1116
+ group_properties = None ,
1100
1117
only_evaluate_locally = False ,
1101
1118
send_feature_flag_events = True ,
1102
1119
disable_geoip = None ,
@@ -1237,9 +1254,9 @@ def get_all_flags(
1237
1254
self ,
1238
1255
distinct_id ,
1239
1256
* ,
1240
- groups = {} ,
1241
- person_properties = {} ,
1242
- group_properties = {} ,
1257
+ groups = None ,
1258
+ person_properties = None ,
1259
+ group_properties = None ,
1243
1260
only_evaluate_locally = False ,
1244
1261
disable_geoip = None ,
1245
1262
) -> Optional [dict [str , Union [bool , str ]]]:
@@ -1258,9 +1275,9 @@ def get_all_flags_and_payloads(
1258
1275
self ,
1259
1276
distinct_id ,
1260
1277
* ,
1261
- groups = {} ,
1262
- person_properties = {} ,
1263
- group_properties = {} ,
1278
+ groups = None ,
1279
+ person_properties = None ,
1280
+ group_properties = None ,
1264
1281
only_evaluate_locally = False ,
1265
1282
disable_geoip = None ,
1266
1283
) -> FlagsAndPayloads :
@@ -1302,10 +1319,13 @@ def _get_all_flags_and_payloads_locally(
1302
1319
distinct_id : ID_TYPES ,
1303
1320
* ,
1304
1321
groups : Dict [str , Union [str , int ]],
1305
- person_properties = {} ,
1306
- group_properties = {} ,
1322
+ person_properties = None ,
1323
+ group_properties = None ,
1307
1324
warn_on_unknown_groups = False ,
1308
1325
) -> tuple [FlagsAndPayloads , bool ]:
1326
+ person_properties = person_properties or {}
1327
+ group_properties = group_properties or {}
1328
+
1309
1329
if self .feature_flags is None and self .personal_api_key :
1310
1330
self .load_feature_flags ()
1311
1331
0 commit comments