MCPcopy Index your code
hub / github.com/python/cpython / _format

Method _format

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

Source from the content-addressed store, hash-verified

187 return readable and not recursive
188
189 def _format(self, object, stream, indent, allowance, context, level):
190 objid = id(object)
191 if objid in context:
192 stream.write(_recursion(object))
193 self._recursive = True
194 self._readable = False
195 return
196 rep = self._repr(object, context, level)
197 max_width = self._width - indent - allowance
198 if len(rep) > max_width:
199 p = self._dispatch.get(type(object).__repr__, None)
200 # Lazy import to improve module import time
201 from dataclasses import is_dataclass
202
203 if p is not None:
204 context[objid] = 1
205 p(self, object, stream, indent, allowance, context, level + 1)
206 del context[objid]
207 return
208 elif (is_dataclass(object) and
209 not isinstance(object, type) and
210 object.__dataclass_params__.repr and
211 # Check dataclass has generated repr method.
212 hasattr(object.__repr__, "__wrapped__") and
213 "__create_fn__" in object.__repr__.__wrapped__.__qualname__):
214 context[objid] = 1
215 self._pprint_dataclass(object, stream, indent, allowance, context, level + 1)
216 del context[objid]
217 return
218 stream.write(rep)
219
220 def _format_block_start(self, start_str, indent):
221 if self._expand:

Callers 12

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 8

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

Tested by

no test coverage detected