Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 035f7e8

Browse files
committed
Clarify __repr__ and __str__.
1 parent 5b56765 commit 035f7e8

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

Doc/ref/ref3.tex

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -910,12 +910,15 @@ \subsection{Basic customization\label{customization}}
910910
\begin{methoddesc}[object]{__repr__}{self}
911911
Called by the \function{repr()}\bifuncindex{repr} built-in function
912912
and by string conversions (reverse quotes) to compute the ``official''
913-
string representation of an object. This should normally look like a
914-
valid Python expression that can be used to recreate an object with
915-
the same value. By convention, objects which cannot be trivially
916-
converted to strings which can be used to create a similar object
917-
produce a string of the form \samp{<\var{...some useful
918-
description...}>}.
913+
string representation of an object. It at all possible, this should
914+
look like a valid Python expression that could be used to recreate an
915+
object with the same value (given an appropriate environment). If
916+
this is not possible, a string of the form \samp{<\var{...some useful
917+
description...}>} should be returned. The return value must be a
918+
string object.
919+
920+
This is typically used for debugging, so it is important that the
921+
representation is information-rich and unambiguous.
919922
\indexii{string}{conversion}
920923
\indexii{reverse}{quotes}
921924
\indexii{backward}{quotes}
@@ -928,7 +931,7 @@ \subsection{Basic customization\label{customization}}
928931
``informal'' string representation of an object. This differs from
929932
\method{__repr__()} in that it does not have to be a valid Python
930933
expression: a more convenient or concise representation may be used
931-
instead.
934+
instead. The return value must be a string object.
932935
\end{methoddesc}
933936

934937
\begin{methoddesc}[object]{__cmp__}{self, other}

0 commit comments

Comments
 (0)