mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Add an experimental mechanism to support extending the pprint formatting.
Partly responds to SF bug #505152.
This commit is contained in:
parent
4993c51b94
commit
aee113d368
3 changed files with 57 additions and 9 deletions
|
@ -173,3 +173,26 @@ this returns false.
|
|||
\begin{methoddesc}{isrecursive}{object}
|
||||
Determine if the object requires a recursive representation.
|
||||
\end{methoddesc}
|
||||
|
||||
This method is provided as a hook to allow subclasses to modify the
|
||||
way objects are converted to strings. The default implementation uses
|
||||
the internals of the \function{saferepr()} implementation.
|
||||
|
||||
\begin{methoddesc}{format}{object, context, maxlevels, level}
|
||||
Returns three values: the formatted version of \var{object} as a
|
||||
string, a flag indicating whether the result is readable, and a flag
|
||||
indicating whether recursion was detected. The first argument is the
|
||||
object to be presented. The second is a dictionary which contains the
|
||||
\function{id()} of objects that are part of the current presentation
|
||||
context (direct and indirect containers for \var{object} that are
|
||||
affecting the presentation) as the keys; if an object needs to be
|
||||
presented which is already represented in \var{context}, the third
|
||||
return value should be true. Recursive calls to the \method{format()}
|
||||
method should add additionaly entries for containers to this
|
||||
dictionary. The fourth argument, \var{maxlevels}, gives the requested
|
||||
limit to recursion; this will be \code{0} if there is no requested
|
||||
limit. This argument should be passed unmodified to recursive calls.
|
||||
The fourth argument, \var{level} gives the current level; recursive
|
||||
calls should be passed a value less than that of the current call.
|
||||
\versionadded{2.3}
|
||||
\end{methoddesc}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue