@@ -331,12 +331,17 @@ class in_type(frozendict):
331331 else :
332332 in_type = frozendict
333333
334- msg = in_type ({FruitStr .BANANA : 1 , "b" : [FruitInt .APPLE ], 3 : "three" })
334+ raw = {FruitStr .BANANA : 1 , "b" : [FruitInt .APPLE ], 3 : "three" }
335+ msg = in_type (raw )
335336
336337 res = to_builtins (msg )
337338 self .check_non_frozen (res , {"banana" : 1 , "b" : [- 1 ], 3 : "three" })
338339 assert res is not msg
339340
341+ self .check_non_frozen (
342+ to_builtins (raw , builtin_types = [frozendict ]),
343+ {"banana" : 1 , "b" : [- 1 ], 3 : "three" },
344+ )
340345 self .check_non_frozen (to_builtins (in_type ()), {})
341346
342347 @py315_or_later_only
@@ -349,13 +354,22 @@ def test_frozendict_builtin_types(self):
349354 frozendict (
350355 {
351356 "test" : frozendict ({1 : "a" }),
357+ FruitStr .BANANA : 1 ,
358+ "b" : [FruitInt .APPLE ],
352359 }
353360 ),
354361 builtin_types = (frozendict ,),
355362 )
356363 assert type (msg ) is frozendict
357364 assert type (msg ["test" ]) is frozendict
358- assert msg == frozendict ({"test" : frozendict ({1 : "a" })})
365+ assert type (list (msg .keys ())[1 ]) is str
366+ assert msg == frozendict (
367+ {
368+ "test" : frozendict ({1 : "a" }),
369+ "banana" : 1 ,
370+ "b" : [- 1 ],
371+ }
372+ )
359373
360374 @py315_or_later_only
361375 def test_frozendict_str_subclass_key (self ):
@@ -629,9 +643,9 @@ def test_order_invalid(self):
629643 to_builtins (1 , order = "bad" )
630644
631645 @staticmethod
632- def assert_eq (left , right ):
646+ def assert_eq (left , right , typ = dict ):
633647 assert left == right
634- if isinstance (left , dict ):
648+ if isinstance (left , typ ):
635649 assert list (left ) == list (right )
636650
637651 @pytest .mark .parametrize ("msg" , [{}, {"y" : 1 , "x" : 2 , "z" : 3 }])
@@ -649,6 +663,15 @@ def test_order_dict_unsortable(self):
649663 with pytest .raises (TypeError ):
650664 to_builtins ({"x" : 1 , 1 : 2 }, order = "deterministic" )
651665
666+ @py315_or_later_only
667+ @pytest .mark .parametrize ("msg" , [{}, {"y" : 1 , "x" : 2 , "z" : 3 }])
668+ @pytest .mark .parametrize ("order" , [None , "deterministic" , "sorted" ])
669+ def test_frozendict_builtin_types_sorted (self , msg , order ):
670+ msg = frozendict (msg )
671+ res = to_builtins (msg , builtin_types = [frozendict ], order = order )
672+ sol = frozendict (sorted (msg .items ())) if order else msg
673+ self .assert_eq (res , sol , typ = frozendict )
674+
652675 @pytest .mark .parametrize ("typ" , [set , frozenset ])
653676 @pytest .mark .parametrize ("order" , ["deterministic" , "sorted" ])
654677 def test_order_set (self , typ , rand , order ):
0 commit comments