MCPcopy Index your code
hub / github.com/RustPython/RustPython / _format

Method _format

Lib/pprint.py:177–206  ·  view source on GitHub ↗
(self, object, stream, indent, allowance, context, level)

Source from the content-addressed store, hash-verified

175 return readable and not recursive
176
177 def _format(self, object, stream, indent, allowance, context, level):
178 objid = id(object)
179 if objid in context:
180 stream.write(_recursion(object))
181 self._recursive = True
182 self._readable = False
183 return
184 rep = self._repr(object, context, level)
185 max_width = self._width - indent - allowance
186 if len(rep) > max_width:
187 p = self._dispatch.get(type(object).__repr__, None)
188 # Lazy import to improve module import time
189 from dataclasses import is_dataclass
190
191 if p is not None:
192 context[objid] = 1
193 p(self, object, stream, indent, allowance, context, level + 1)
194 del context[objid]
195 return
196 elif (is_dataclass(object) and
197 not isinstance(object, type) and
198 object.__dataclass_params__.repr and
199 # Check dataclass has generated repr method.
200 hasattr(object.__repr__, "__wrapped__") and
201 "__create_fn__" in object.__repr__.__wrapped__.__qualname__):
202 context[objid] = 1
203 self._pprint_dataclass(object, stream, indent, allowance, context, level + 1)
204 del context[objid]
205 return
206 stream.write(rep)
207
208 def _pprint_dataclass(self, object, stream, indent, allowance, context, level):
209 # Lazy import to improve module import time

Callers 11

pprintMethod · 0.95
pformatMethod · 0.95
_pprint_ordered_dictMethod · 0.95
_pprint_mappingproxyMethod · 0.95
_format_dict_itemsMethod · 0.95
_format_itemsMethod · 0.95
_pprint_chain_mapMethod · 0.95
_pprint_user_dictMethod · 0.95
_pprint_user_listMethod · 0.95
_pprint_user_stringMethod · 0.95

Calls 11

_reprMethod · 0.95
_pprint_dataclassMethod · 0.95
is_dataclassFunction · 0.90
idFunction · 0.85
_recursionFunction · 0.85
lenFunction · 0.85
isinstanceFunction · 0.85
hasattrFunction · 0.85
pFunction · 0.70
writeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected