[docs] Improve doc for str(bytesobject) (issue 13538)
chris.jerdonek at gmail.com
chris.jerdonek at gmail.com
Sat Nov 17 22:37:49 CET 2012
http://bugs.python.org/review/13538/diff/6548/Doc/library/functions.rst
File Doc/library/functions.rst (right):
http://bugs.python.org/review/13538/diff/6548/Doc/library/functions.rst#newcode1264
Doc/library/functions.rst:1264: :meth:`object.__str__`, which is the
"informal" representation of *object*.
On 2012/11/17 17:09:02, ezio.melotti wrote:
> Why not keeping the "nicely printable representation" used in the
original text?
I switched to using the same language that the object.__str__()
documentation used. I can include both phrasings as that documentation
now includes both.
http://bugs.python.org/review/13538/diff/6548/Doc/library/functions.rst#newcode1264
Doc/library/functions.rst:1264: :meth:`object.__str__`, which is the
"informal" representation of *object*.
On 2012/11/17 17:09:02, ezio.melotti wrote:
> Doesn't it also fall back on __repr__ if __str__ is missing?
str() (unicode_new() in the source code) only calls object.__str__()
(PyObject_Str() in the source code):
http://hg.python.org/cpython/file/e9af9b1ca67e/Objects/unicodeobject.c#l14012
The fallback logic is part of PyObject_Str:
http://hg.python.org/cpython/file/e9af9b1ca67e/Objects/object.c#l396
which is documented as part of the object.__str__() documentation (which
is linked to). You can confirm this by defining a class that defines
__repr__() but not __str__(), and then calling __str__() on it:
>>> class Foo(object):
... def __repr__(self):
... return "foo"
...
>>> f = Foo()
>>> f.__str__()
'foo'
http://bugs.python.org/review/13538/diff/6548/Doc/reference/datamodel.rst
File Doc/reference/datamodel.rst (right):
http://bugs.python.org/review/13538/diff/6548/Doc/reference/datamodel.rst#newcode1176
Doc/reference/datamodel.rst:1176: back to calling :meth:`__repr__`.
On 2012/11/17 17:09:02, ezio.melotti wrote:
> Where does this happen? Is it done by str/print or it happens
automatically?
It's done in PyObject_Str. See my reply to your other comment in
functions.rst.
http://bugs.python.org/review/13538/
More information about the docs
mailing list