@@ -218,7 +218,7 @@ def _populate_path_params(
218218 if isinstance (param , List ):
219219 pp_vals : List [str ] = []
220220 for pp_val in param :
221- if pp_val is None :
221+ if pp_val is None or pp_val == "__SPEAKEASY_UNSET__" :
222222 continue
223223 pp_vals .append (_val_to_string (pp_val ))
224224 path_param_values [param_metadata .get ("field_name" , field .name )] = (
@@ -227,7 +227,10 @@ def _populate_path_params(
227227 elif isinstance (param , Dict ):
228228 pp_vals : List [str ] = []
229229 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+ ):
231234 continue
232235 if param_metadata .get ("explode" ):
233236 pp_vals .append (f"{ pp_key } ={ _val_to_string (param [pp_key ])} " )
@@ -247,7 +250,10 @@ def _populate_path_params(
247250 param_name = param_value_metadata .get ("field_name" , field .name )
248251
249252 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+ ):
251257 continue
252258 if param_metadata .get ("explode" ):
253259 pp_vals .append (
@@ -406,19 +412,23 @@ def _get_serialized_params(
406412def _populate_deep_object_query_params (
407413 metadata : Dict , field_name : str , obj : Any , params : Dict [str , List [str ]]
408414):
409- if obj is None :
415+ if obj is None or obj == "__SPEAKEASY_UNSET__" :
410416 return
411417
412418 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+ )
414422 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+ )
416426
417427
418428def _populate_deep_object_query_params_dataclass (
419429 prior_params_key : str , obj : Any , params : Dict [str , List [str ]]
420430):
421- if obj is None :
431+ if obj is None or obj == "__SPEAKEASY_UNSET__" :
422432 return
423433
424434 if not is_dataclass (obj ):
@@ -431,7 +441,7 @@ def _populate_deep_object_query_params_dataclass(
431441 continue
432442
433443 obj_val = getattr (obj , obj_field .name )
434- if obj_val is None :
444+ if obj_val is None or obj_val == "__SPEAKEASY_UNSET__" :
435445 continue
436446
437447 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(
449459def _populate_deep_object_query_params_dict (
450460 prior_params_key : str , value : Dict , params : Dict [str , List [str ]]
451461):
452- if value is None :
462+ if value is None or value == "__SPEAKEASY_UNSET__" :
453463 return
454464
455465 for key , val in value .items ():
456- if val is None :
466+ if val is None or val == "__SPEAKEASY_UNSET__" :
457467 continue
458468
459- params_key = f' { prior_params_key } [{ key } ]'
469+ params_key = f" { prior_params_key } [{ key } ]"
460470
461471 if is_dataclass (val ):
462472 _populate_deep_object_query_params_dataclass (params_key , val , params )
@@ -471,11 +481,11 @@ def _populate_deep_object_query_params_dict(
471481def _populate_deep_object_query_params_list (
472482 params_key : str , value : List , params : Dict [str , List [str ]]
473483):
474- if value is None :
484+ if value is None or value == "__SPEAKEASY_UNSET__" :
475485 return
476486
477487 for val in value :
478- if val is None :
488+ if val is None or val == "__SPEAKEASY_UNSET__" :
479489 continue
480490
481491 if params .get (params_key ) is None :
@@ -593,7 +603,7 @@ def serialize_multipart_form(
593603
594604 for field in request_fields :
595605 val = getattr (request , field .name )
596- if val is None :
606+ if val is None or val == "__SPEAKEASY_UNSET__" :
597607 continue
598608
599609 field_metadata = field .metadata .get ("multipart_form" )
@@ -631,10 +641,12 @@ def serialize_multipart_form(
631641 field_name = field_metadata .get ("field_name" , field .name )
632642 if isinstance (val , List ):
633643 for value in val :
634- if value is None :
644+ if value is None or value == "__SPEAKEASY_UNSET__" :
635645 continue
636646 form .append ([field_name + "[]" , [None , _val_to_string (value )]])
637647 else :
648+ if val == "__SPEAKEASY_UNSET__" :
649+ continue
638650 form .append ([field_name , [None , _val_to_string (val )]])
639651 return media_type , None , form
640652
@@ -667,7 +679,7 @@ def serialize_form_data(field_name: str, data: Any) -> Dict[str, Any]:
667679 if is_dataclass (data ):
668680 for field in fields (data ):
669681 val = getattr (data , field .name )
670- if val is None :
682+ if val is None or val == "__SPEAKEASY_UNSET__" :
671683 continue
672684
673685 metadata = field .metadata .get ("form" )
@@ -692,6 +704,8 @@ def serialize_form_data(field_name: str, data: Any) -> Dict[str, Any]:
692704 raise Exception (f"Invalid form style for field { field .name } " )
693705 elif isinstance (data , Dict ):
694706 for key , value in data .items ():
707+ if value == "__SPEAKEASY_UNSET__" :
708+ continue
695709 form [key ] = [_val_to_string (value )]
696710 else :
697711 raise Exception (f"Invalid request body type for field { field_name } " )
@@ -716,7 +730,7 @@ def _populate_form(
716730 delimiter : str ,
717731 form : Dict [str , List [str ]],
718732):
719- if obj is None :
733+ if obj is None or obj == "__SPEAKEASY_UNSET__" :
720734 return form
721735
722736 if is_dataclass (obj ):
@@ -729,7 +743,7 @@ def _populate_form(
729743 continue
730744
731745 val = getattr (obj , obj_field .name )
732- if val is None :
746+ if val is None or val == "__SPEAKEASY_UNSET__" :
733747 continue
734748
735749 if explode :
@@ -742,7 +756,7 @@ def _populate_form(
742756 elif isinstance (obj , Dict ):
743757 items = []
744758 for key , value in obj .items ():
745- if value is None :
759+ if value is None or value == "__SPEAKEASY_UNSET__" :
746760 continue
747761
748762 if explode :
@@ -756,7 +770,7 @@ def _populate_form(
756770 items = []
757771
758772 for value in obj :
759- if value is None :
773+ if value is None or value == "__SPEAKEASY_UNSET__" :
760774 continue
761775
762776 if explode :
@@ -769,13 +783,14 @@ def _populate_form(
769783 if len (items ) > 0 :
770784 form [field_name ] = [delimiter .join ([str (item ) for item in items ])]
771785 else :
772- form [field_name ] = [_val_to_string (obj )]
786+ if obj != "__SPEAKEASY_UNSET__" :
787+ form [field_name ] = [_val_to_string (obj )]
773788
774789 return form
775790
776791
777792def _serialize_header (explode : bool , obj : Any ) -> str :
778- if obj is None :
793+ if obj is None or obj == "__SPEAKEASY_UNSET__" :
779794 return ""
780795
781796 if is_dataclass (obj ):
@@ -792,7 +807,7 @@ def _serialize_header(explode: bool, obj: Any) -> str:
792807 continue
793808
794809 val = getattr (obj , obj_field .name )
795- if val is None :
810+ if val is None or val == "__SPEAKEASY_UNSET__" :
796811 continue
797812
798813 if explode :
@@ -807,7 +822,7 @@ def _serialize_header(explode: bool, obj: Any) -> str:
807822 items = []
808823
809824 for key , value in obj .items ():
810- if value is None :
825+ if value is None or value == "__SPEAKEASY_UNSET__" :
811826 continue
812827
813828 if explode :
@@ -822,14 +837,16 @@ def _serialize_header(explode: bool, obj: Any) -> str:
822837 items = []
823838
824839 for value in obj :
825- if value is None :
840+ if value is None or value == "__SPEAKEASY_UNSET__" :
826841 continue
827842
828843 items .append (_val_to_string (value ))
829844
830845 if len (items ) > 0 :
831846 return "," .join (items )
832847 else :
848+ if obj == "__SPEAKEASY_UNSET__" :
849+ return ""
833850 return f"{ _val_to_string (obj )} "
834851
835852 return ""
@@ -928,6 +945,7 @@ def bigintdecoder(val):
928945 raise ValueError (f"{ val } is a float" )
929946 return int (val )
930947
948+
931949def integerstrencoder (optional : bool ):
932950 def integerstrencode (val : int ):
933951 if optional and val is None :
@@ -1114,3 +1132,15 @@ def remove_suffix(input_string, suffix):
11141132 if suffix and input_string .endswith (suffix ):
11151133 return input_string [: - len (suffix )]
11161134 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