@@ -1039,6 +1039,24 @@ def test_depth(self):
10391039 self .assertEqual (pprint .pformat (nested_dict , depth = 1 ), lv1_dict )
10401040 self .assertEqual (pprint .pformat (nested_list , depth = 1 ), lv1_list )
10411041
1042+ def test_depth_with_narrow_width (self ):
1043+ # gh-89774: a narrow width must not override the depth limit.
1044+ nested_dict = {1 : {2 : {3 : 3 }}}
1045+ nested_list = [1 , [2 , [3 , [4 ]]]]
1046+ nested_tuple = (1 , (2 , (3 ,)))
1047+ self .assertEqual (pprint .pformat (nested_dict , depth = 1 , width = 5 ),
1048+ '{1: {...}}' )
1049+ self .assertEqual (pprint .pformat (nested_dict , depth = 2 , width = 5 ),
1050+ '{1: {2: {...}}}' )
1051+ self .assertEqual (pprint .pformat (nested_list , depth = 1 , width = 6 ),
1052+ '[1,\n [...]]' )
1053+ self .assertEqual (pprint .pformat (nested_tuple , depth = 1 , width = 6 ),
1054+ '(1,\n (...))' )
1055+ # Depth folding is independent of width: a narrow width folds at the
1056+ # same level as the default wide width.
1057+ self .assertEqual (pprint .pformat (nested_dict , depth = 1 , width = 5 ),
1058+ pprint .pformat (nested_dict , depth = 1 ))
1059+
10421060 def test_sort_unorderable_values (self ):
10431061 # Issue 3976: sorted pprints fail for unorderable values.
10441062 n = 20
0 commit comments