@@ -105,26 +105,34 @@ def _make_open(self, char: str, indent: int, obj):
105
105
else :
106
106
the_indent = ' ' * (indent + self ._indent_per_level )
107
107
108
- if len ( obj ) and not self ._compact : # type: ignore
108
+ if obj and not self ._compact : # type: ignore
109
109
return f"{ char } \n { the_indent } "
110
110
else :
111
111
return char
112
112
113
113
def _make_close (self , char : str , indent : int , obj ):
114
- if len ( obj ) and not self ._compact : # type: ignore
114
+ if obj and not self ._compact : # type: ignore
115
115
return f",\n { ' ' * (indent + self ._indent_per_level )} { char } "
116
116
else :
117
117
return char
118
118
119
- def _pprint_dict (self , object , stream , indent , allowance , context , level ): # noqa: A002
119
+ def _pprint_dict (
120
+ self ,
121
+ object , # noqa: A002 # pylint: disable=redefined-builtin
122
+ stream ,
123
+ indent ,
124
+ allowance ,
125
+ context ,
126
+ level ,
127
+ ):
120
128
obj = object
121
129
write = stream .write
122
130
write (self ._make_open ('{' , indent , obj ))
123
131
124
132
if self ._indent_per_level > 1 :
125
133
write ((self ._indent_per_level - 1 ) * ' ' )
126
134
127
- if len ( obj ) :
135
+ if obj :
128
136
self ._format_dict_items ( # type: ignore
129
137
obj .items (),
130
138
stream ,
@@ -154,9 +162,10 @@ def _pprint_tuple(self, obj, stream, indent, allowance, context, level):
154
162
_dispatch [tuple .__repr__ ] = _pprint_tuple
155
163
156
164
def _pprint_set (self , obj , stream , indent , allowance , context , level ):
157
- if not len ( obj ) :
165
+ if not obj :
158
166
stream .write (repr (obj ))
159
167
return
168
+
160
169
typ = obj .__class__
161
170
if typ is set :
162
171
stream .write (self ._make_open ('{' , indent , obj ))
@@ -165,6 +174,7 @@ def _pprint_set(self, obj, stream, indent, allowance, context, level):
165
174
stream .write (typ .__name__ + f"({{\n { ' ' * (indent + self ._indent_per_level + len (typ .__name__ ) + 1 )} " )
166
175
endchar = f",\n { ' ' * (indent + self ._indent_per_level + len (typ .__name__ ) + 1 )} }})"
167
176
indent += len (typ .__name__ ) + 1
177
+
168
178
obj = sorted (obj , key = _safe_key )
169
179
self ._format_items (obj , stream , indent , allowance + len (endchar ), context , level )
170
180
stream .write (endchar )
@@ -205,7 +215,7 @@ def format_attributes(self, obj: Attributes):
205
215
if self ._indent_per_level > 1 :
206
216
stream .write ((self ._indent_per_level - 1 ) * ' ' )
207
217
208
- if len ( obj ) :
218
+ if obj :
209
219
self ._format_attribute_items (list (obj ), stream , 0 , 0 + 1 , context , 1 )
210
220
stream .write (f"\n { self ._indent_per_level * ' ' } )" )
211
221
0 commit comments