@@ -218,7 +218,7 @@ def _populate_path_params(
218
218
if isinstance (param , List ):
219
219
pp_vals : List [str ] = []
220
220
for pp_val in param :
221
- if pp_val is None :
221
+ if pp_val is None or pp_val == "__SPEAKEASY_UNSET__" :
222
222
continue
223
223
pp_vals .append (_val_to_string (pp_val ))
224
224
path_param_values [param_metadata .get ("field_name" , field .name )] = (
@@ -227,7 +227,10 @@ def _populate_path_params(
227
227
elif isinstance (param , Dict ):
228
228
pp_vals : List [str ] = []
229
229
for pp_key in param :
230
- if param [pp_key ] is None :
230
+ if (
231
+ param [pp_key ] is None
232
+ or param [pp_key ] == "__SPEAKEASY_UNSET__"
233
+ ):
231
234
continue
232
235
if param_metadata .get ("explode" ):
233
236
pp_vals .append (f"{ pp_key } ={ _val_to_string (param [pp_key ])} " )
@@ -247,7 +250,10 @@ def _populate_path_params(
247
250
param_name = param_value_metadata .get ("field_name" , field .name )
248
251
249
252
param_field_val = getattr (param , param_field .name )
250
- if param_field_val is None :
253
+ if (
254
+ param_field_val is None
255
+ or param_field_val == "__SPEAKEASY_UNSET__"
256
+ ):
251
257
continue
252
258
if param_metadata .get ("explode" ):
253
259
pp_vals .append (
@@ -406,19 +412,23 @@ def _get_serialized_params(
406
412
def _populate_deep_object_query_params (
407
413
metadata : Dict , field_name : str , obj : Any , params : Dict [str , List [str ]]
408
414
):
409
- if obj is None :
415
+ if obj is None or obj == "__SPEAKEASY_UNSET__" :
410
416
return
411
417
412
418
if is_dataclass (obj ):
413
- _populate_deep_object_query_params_dataclass (metadata .get ("field_name" , field_name ), obj , params )
419
+ _populate_deep_object_query_params_dataclass (
420
+ metadata .get ("field_name" , field_name ), obj , params
421
+ )
414
422
elif isinstance (obj , Dict ):
415
- _populate_deep_object_query_params_dict (metadata .get ("field_name" , field_name ), obj , params )
423
+ _populate_deep_object_query_params_dict (
424
+ metadata .get ("field_name" , field_name ), obj , params
425
+ )
416
426
417
427
418
428
def _populate_deep_object_query_params_dataclass (
419
429
prior_params_key : str , obj : Any , params : Dict [str , List [str ]]
420
430
):
421
- if obj is None :
431
+ if obj is None or obj == "__SPEAKEASY_UNSET__" :
422
432
return
423
433
424
434
if not is_dataclass (obj ):
@@ -431,7 +441,7 @@ def _populate_deep_object_query_params_dataclass(
431
441
continue
432
442
433
443
obj_val = getattr (obj , obj_field .name )
434
- if obj_val is None :
444
+ if obj_val is None or obj_val == "__SPEAKEASY_UNSET__" :
435
445
continue
436
446
437
447
params_key = f'{ prior_params_key } [{ obj_param_metadata .get ("field_name" , obj_field .name )} ]'
@@ -449,14 +459,14 @@ def _populate_deep_object_query_params_dataclass(
449
459
def _populate_deep_object_query_params_dict (
450
460
prior_params_key : str , value : Dict , params : Dict [str , List [str ]]
451
461
):
452
- if value is None :
462
+ if value is None or value == "__SPEAKEASY_UNSET__" :
453
463
return
454
464
455
465
for key , val in value .items ():
456
- if val is None :
466
+ if val is None or val == "__SPEAKEASY_UNSET__" :
457
467
continue
458
468
459
- params_key = f' { prior_params_key } [{ key } ]'
469
+ params_key = f" { prior_params_key } [{ key } ]"
460
470
461
471
if is_dataclass (val ):
462
472
_populate_deep_object_query_params_dataclass (params_key , val , params )
@@ -471,11 +481,11 @@ def _populate_deep_object_query_params_dict(
471
481
def _populate_deep_object_query_params_list (
472
482
params_key : str , value : List , params : Dict [str , List [str ]]
473
483
):
474
- if value is None :
484
+ if value is None or value == "__SPEAKEASY_UNSET__" :
475
485
return
476
486
477
487
for val in value :
478
- if val is None :
488
+ if val is None or val == "__SPEAKEASY_UNSET__" :
479
489
continue
480
490
481
491
if params .get (params_key ) is None :
@@ -593,7 +603,7 @@ def serialize_multipart_form(
593
603
594
604
for field in request_fields :
595
605
val = getattr (request , field .name )
596
- if val is None :
606
+ if val is None or val == "__SPEAKEASY_UNSET__" :
597
607
continue
598
608
599
609
field_metadata = field .metadata .get ("multipart_form" )
@@ -631,10 +641,12 @@ def serialize_multipart_form(
631
641
field_name = field_metadata .get ("field_name" , field .name )
632
642
if isinstance (val , List ):
633
643
for value in val :
634
- if value is None :
644
+ if value is None or value == "__SPEAKEASY_UNSET__" :
635
645
continue
636
646
form .append ([field_name + "[]" , [None , _val_to_string (value )]])
637
647
else :
648
+ if val == "__SPEAKEASY_UNSET__" :
649
+ continue
638
650
form .append ([field_name , [None , _val_to_string (val )]])
639
651
return media_type , None , form
640
652
@@ -667,7 +679,7 @@ def serialize_form_data(field_name: str, data: Any) -> Dict[str, Any]:
667
679
if is_dataclass (data ):
668
680
for field in fields (data ):
669
681
val = getattr (data , field .name )
670
- if val is None :
682
+ if val is None or val == "__SPEAKEASY_UNSET__" :
671
683
continue
672
684
673
685
metadata = field .metadata .get ("form" )
@@ -692,6 +704,8 @@ def serialize_form_data(field_name: str, data: Any) -> Dict[str, Any]:
692
704
raise Exception (f"Invalid form style for field { field .name } " )
693
705
elif isinstance (data , Dict ):
694
706
for key , value in data .items ():
707
+ if value == "__SPEAKEASY_UNSET__" :
708
+ continue
695
709
form [key ] = [_val_to_string (value )]
696
710
else :
697
711
raise Exception (f"Invalid request body type for field { field_name } " )
@@ -716,7 +730,7 @@ def _populate_form(
716
730
delimiter : str ,
717
731
form : Dict [str , List [str ]],
718
732
):
719
- if obj is None :
733
+ if obj is None or obj == "__SPEAKEASY_UNSET__" :
720
734
return form
721
735
722
736
if is_dataclass (obj ):
@@ -729,7 +743,7 @@ def _populate_form(
729
743
continue
730
744
731
745
val = getattr (obj , obj_field .name )
732
- if val is None :
746
+ if val is None or val == "__SPEAKEASY_UNSET__" :
733
747
continue
734
748
735
749
if explode :
@@ -742,7 +756,7 @@ def _populate_form(
742
756
elif isinstance (obj , Dict ):
743
757
items = []
744
758
for key , value in obj .items ():
745
- if value is None :
759
+ if value is None or value == "__SPEAKEASY_UNSET__" :
746
760
continue
747
761
748
762
if explode :
@@ -756,7 +770,7 @@ def _populate_form(
756
770
items = []
757
771
758
772
for value in obj :
759
- if value is None :
773
+ if value is None or value == "__SPEAKEASY_UNSET__" :
760
774
continue
761
775
762
776
if explode :
@@ -769,13 +783,14 @@ def _populate_form(
769
783
if len (items ) > 0 :
770
784
form [field_name ] = [delimiter .join ([str (item ) for item in items ])]
771
785
else :
772
- form [field_name ] = [_val_to_string (obj )]
786
+ if obj != "__SPEAKEASY_UNSET__" :
787
+ form [field_name ] = [_val_to_string (obj )]
773
788
774
789
return form
775
790
776
791
777
792
def _serialize_header (explode : bool , obj : Any ) -> str :
778
- if obj is None :
793
+ if obj is None or obj == "__SPEAKEASY_UNSET__" :
779
794
return ""
780
795
781
796
if is_dataclass (obj ):
@@ -792,7 +807,7 @@ def _serialize_header(explode: bool, obj: Any) -> str:
792
807
continue
793
808
794
809
val = getattr (obj , obj_field .name )
795
- if val is None :
810
+ if val is None or val == "__SPEAKEASY_UNSET__" :
796
811
continue
797
812
798
813
if explode :
@@ -807,7 +822,7 @@ def _serialize_header(explode: bool, obj: Any) -> str:
807
822
items = []
808
823
809
824
for key , value in obj .items ():
810
- if value is None :
825
+ if value is None or value == "__SPEAKEASY_UNSET__" :
811
826
continue
812
827
813
828
if explode :
@@ -822,14 +837,16 @@ def _serialize_header(explode: bool, obj: Any) -> str:
822
837
items = []
823
838
824
839
for value in obj :
825
- if value is None :
840
+ if value is None or value == "__SPEAKEASY_UNSET__" :
826
841
continue
827
842
828
843
items .append (_val_to_string (value ))
829
844
830
845
if len (items ) > 0 :
831
846
return "," .join (items )
832
847
else :
848
+ if obj == "__SPEAKEASY_UNSET__" :
849
+ return ""
833
850
return f"{ _val_to_string (obj )} "
834
851
835
852
return ""
@@ -928,6 +945,7 @@ def bigintdecoder(val):
928
945
raise ValueError (f"{ val } is a float" )
929
946
return int (val )
930
947
948
+
931
949
def integerstrencoder (optional : bool ):
932
950
def integerstrencode (val : int ):
933
951
if optional and val is None :
@@ -1114,3 +1132,15 @@ def remove_suffix(input_string, suffix):
1114
1132
if suffix and input_string .endswith (suffix ):
1115
1133
return input_string [: - len (suffix )]
1116
1134
return input_string
1135
+
1136
+
1137
+ def decodeunset (decoder : Optional [Callable ] = None ):
1138
+ def decode (val ):
1139
+ if val == "__SPEAKEASY_UNSET__" :
1140
+ return val
1141
+ if decoder is None :
1142
+ return None
1143
+
1144
+ return decoder (val )
1145
+
1146
+ return decode
0 commit comments