Issue 20150: API change in string formatting with :s option should be documented in What's New. (original) (raw)

The following code:

"{0:s}".format([1,2,3])

no longer works in Python 3.4b1, and gives the following exception:

"{0:s}".format([1,2,3]) Traceback (most recent call last): File "", line 1, in TypeError: non-empty format string passed to object.format

This worked previously in Python 2.6-3.3:

"{0:s}".format([1,2,3]) '[1, 2, 3]'

If this is a deliberate change, it should be included in the 'What's new in Python 3.4'

I believe this has been added to the 3.4 What's New already:

object.format() no longer accepts non-empty format strings, it now raises a TypeError instead. Using a non-empty string has been deprecated since Python 3.2. This change has been made to prevent a situation where previously working (but incorrect) code would start failing if an object gained a format method, which means that your code may now raise a TypeError if you are using an 's' format code with objects that do not have a format method that handles it. See bpo-7994 for background

Closing as resolved.