Message323688
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'
>>> |
|
Date |
User |
Action |
Args |
2018-08-18 00:18:56 | Jason Spencer | set | recipients:
+ Jason Spencer |
2018-08-18 00:18:56 | Jason Spencer | set | messageid: <1534551536.12.0.56676864532.issue34425@psf.upfronthosting.co.za> |
2018-08-18 00:18:55 | Jason Spencer | link | issue34425 messages |
2018-08-18 00:18:54 | Jason Spencer | create | |
|