@@ -782,6 +782,7 @@ def test_default_parameter_assignments(self) -> None:
782782 side_channel = WeakKeyDictionary (),
783783 prefix = None , # This will trigger line 133
784784 comma_round_trip = None , # This will trigger line 136
785+ comma_compact_nulls = False ,
785786 encoder = None ,
786787 serialize_date = lambda dt : dt .isoformat (),
787788 sort = None ,
@@ -1719,6 +1720,7 @@ def test_encode_cycle_detection_raises_on_same_step(self) -> None:
17191720 side_channel = side_channel ,
17201721 prefix = "root" ,
17211722 comma_round_trip = False ,
1723+ comma_compact_nulls = False ,
17221724 encoder = EncodeUtils .encode ,
17231725 serialize_date = EncodeUtils .serialize_date ,
17241726 sort = None ,
@@ -1749,6 +1751,7 @@ def test_encode_cycle_detection_marks_prior_visit_without_raising(self) -> None:
17491751 side_channel = side_channel ,
17501752 prefix = "root" ,
17511753 comma_round_trip = False ,
1754+ comma_compact_nulls = False ,
17521755 encoder = EncodeUtils .encode ,
17531756 serialize_date = EncodeUtils .serialize_date ,
17541757 sort = None ,
@@ -1789,6 +1792,7 @@ def fake_is_non_nullish_primitive(val: t.Any, skip_nulls: bool = False) -> bool:
17891792 side_channel = WeakKeyDictionary (),
17901793 prefix = "root" ,
17911794 comma_round_trip = False ,
1795+ comma_compact_nulls = False ,
17921796 encoder = EncodeUtils .encode ,
17931797 serialize_date = EncodeUtils .serialize_date ,
17941798 sort = None ,
@@ -1881,3 +1885,24 @@ def test_encode_serializes_booleans(
18811885 self , data : t .Mapping [str , t .Any ], list_format : ListFormat , expected : str
18821886 ) -> None :
18831887 assert encode (data , EncodeOptions (list_format = list_format , encode = False )) == expected
1888+
1889+ def test_comma_compact_nulls_skips_none_entries (self ) -> None :
1890+ options = EncodeOptions (
1891+ list_format = ListFormat .COMMA ,
1892+ encode = False ,
1893+ comma_compact_nulls = True ,
1894+ )
1895+ assert encode ({"a" : {"b" : [True , False , None , True ]}}, options ) == "a[b]=true,false,true"
1896+
1897+ def test_comma_compact_nulls_empty_after_filtering_omits_key (self ) -> None :
1898+ options = EncodeOptions (list_format = ListFormat .COMMA , encode = False , comma_compact_nulls = True )
1899+ assert encode ({"a" : [None , None ]}, options ) == ""
1900+
1901+ def test_comma_compact_nulls_preserves_round_trip_marker (self ) -> None :
1902+ options = EncodeOptions (
1903+ list_format = ListFormat .COMMA ,
1904+ encode = False ,
1905+ comma_round_trip = True ,
1906+ comma_compact_nulls = True ,
1907+ )
1908+ assert encode ({"a" : [None , "foo" ]}, options ) == "a[]=foo"
0 commit comments