Why python str.format doesn't call str()
python
Solution
I think this is a (minor) documentation bug. `str.format` calls `str` if you pass the `!s` code in the format string, but `unicode.format` calls `unicode` instead.
The docs were probably written with Python 3 in mind, where all strings are Unicode and `!s` always calls `str`. The whole new formatting system was backported from Python 3.0 into Python 2.6, and it's not shocking that a few ambiguities slipped in through in the docs.
Problem
I have the following class ``` class A(object): def __unicode__(self): return u'A' def __str__(self): return 'AA' >>> u"{}".format(A()) u'A' >>> "{}".format(A()) 'AA' >>> str(A()) 'AA' ``` According to the documentation, "Harold's a clever {0!s}" # Calls str() on the argument first Why is this still return u'A' not u'AA'?? ``` >>> u"{0!s}".format(A()) u'A' ``` I would expect it's the same as ``` >>> u"{}".format(str(A())) u'AA' ```