This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Jason Spencer
Recipients Jason Spencer
Date 2018-08-18.00:18:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1534551536.12.0.56676864532.issue34425@psf.upfronthosting.co.za>
In-reply-to
Content
Objects with __str__ but WITHOUT __format__ are string-convertible and default-to-str formattable.  But the explicit use of '{:s}' as a format string fails to format these objects as expected.  Either it is no longer the case that '{}' and '{:s}' are equivalent format strings, or formatting for {:s} is broken.  Users would not expect the following to be true.

(Tested in 3.5.3 and 3.6.  Maybe be the same in later releases.)

Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class Coord:
...   def __init__(self, a, b):
...     self.a=a
...     self.b=b
...   def __str__(self):
...     return '{:d}:{:d}'.format(self.a, self.b)
... 
>>> c = Coord(3,4)
>>> str(c)
'3:4'
>>> '{:s}'.format(c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported format string passed to Coord.__format__
>>> '{}'.format(c)
'3:4'
>>> '{!s:s}'.format(c)
'3:4'
>>>
History
Date User Action Args
2018-08-18 00:18:56Jason Spencersetrecipients: + Jason Spencer
2018-08-18 00:18:56Jason Spencersetmessageid: <1534551536.12.0.56676864532.issue34425@psf.upfronthosting.co.za>
2018-08-18 00:18:55Jason Spencerlinkissue34425 messages
2018-08-18 00:18:54Jason Spencercreate