@@ -396,11 +396,11 @@ def __init__(
396396 def do_draw (self , data : ConjectureData ) -> dict [Any , Any ]:
397397 context = current_build_context ()
398398 arg_labels : ArgLabelsT = {}
399- value = type ( self . mapping )()
399+ pairs : list [ tuple [ Any , Any ]] = []
400400
401401 for key , strategy in self .mapping .items ():
402402 with context .track_arg_label (str (key )) as arg_label :
403- value [ key ] = data .draw (strategy )
403+ pairs . append (( key , data .draw (strategy )) )
404404 arg_labels |= arg_label
405405
406406 if self .optional is not None :
@@ -416,9 +416,14 @@ def do_draw(self, data: ConjectureData) -> dict[Any, Any]:
416416 remaining [- 1 ], remaining [j ] = remaining [j ], remaining [- 1 ]
417417 key = remaining .pop ()
418418 with context .track_arg_label (str (key )) as arg_label :
419- value [ key ] = data .draw (self .optional [key ])
419+ pairs . append (( key , data .draw (self .optional [key ])) )
420420 arg_labels |= arg_label
421421
422+ # Vary the dict's iteration order (#3906). We shuffle after choosing
423+ # the optional keys, so only order varies, not the set of keys.
424+ cu .fisher_yates_shuffle (data , pairs )
425+ value = type (self .mapping )(pairs )
426+
422427 if arg_labels :
423428 context .known_object_printers [IDKey (value )].append (
424429 _fixeddict_pprinter (arg_labels , self .mapping )
0 commit comments