@@ -105,26 +105,34 @@ def _make_open(self, char: str, indent: int, obj):
105105 else :
106106 the_indent = ' ' * (indent + self ._indent_per_level )
107107
108- if len ( obj ) and not self ._compact : # type: ignore
108+ if obj and not self ._compact : # type: ignore
109109 return f"{ char } \n { the_indent } "
110110 else :
111111 return char
112112
113113 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
115115 return f",\n { ' ' * (indent + self ._indent_per_level )} { char } "
116116 else :
117117 return char
118118
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+ ):
120128 obj = object
121129 write = stream .write
122130 write (self ._make_open ('{' , indent , obj ))
123131
124132 if self ._indent_per_level > 1 :
125133 write ((self ._indent_per_level - 1 ) * ' ' )
126134
127- if len ( obj ) :
135+ if obj :
128136 self ._format_dict_items ( # type: ignore
129137 obj .items (),
130138 stream ,
@@ -154,9 +162,10 @@ def _pprint_tuple(self, obj, stream, indent, allowance, context, level):
154162 _dispatch [tuple .__repr__ ] = _pprint_tuple
155163
156164 def _pprint_set (self , obj , stream , indent , allowance , context , level ):
157- if not len ( obj ) :
165+ if not obj :
158166 stream .write (repr (obj ))
159167 return
168+
160169 typ = obj .__class__
161170 if typ is set :
162171 stream .write (self ._make_open ('{' , indent , obj ))
@@ -165,6 +174,7 @@ def _pprint_set(self, obj, stream, indent, allowance, context, level):
165174 stream .write (typ .__name__ + f"({{\n { ' ' * (indent + self ._indent_per_level + len (typ .__name__ ) + 1 )} " )
166175 endchar = f",\n { ' ' * (indent + self ._indent_per_level + len (typ .__name__ ) + 1 )} }})"
167176 indent += len (typ .__name__ ) + 1
177+
168178 obj = sorted (obj , key = _safe_key )
169179 self ._format_items (obj , stream , indent , allowance + len (endchar ), context , level )
170180 stream .write (endchar )
@@ -205,7 +215,7 @@ def format_attributes(self, obj: Attributes):
205215 if self ._indent_per_level > 1 :
206216 stream .write ((self ._indent_per_level - 1 ) * ' ' )
207217
208- if len ( obj ) :
218+ if obj :
209219 self ._format_attribute_items (list (obj ), stream , 0 , 0 + 1 , context , 1 )
210220 stream .write (f"\n { self ._indent_per_level * ' ' } )" )
211221
0 commit comments