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 eric.smith
Recipients docs@python, eric.smith, py.user, r.david.murray, terry.reedy
Date 2012-01-21.00:16:21
SpamBayes Score 4.8701883e-09
Marked as misclassified No
Message-id <1327104985.35.0.90065015845.issue13790@psf.upfronthosting.co.za>
In-reply-to
Content
I don't think "{}" is the correct way to document this. These all have an empty format specifier:

"{}".format(foo)
"{:}".format(foo)
"{0}".format(foo)
"{0:}".format(foo)
"{name}".format(name=foo)
format(foo, "")
format(foo)

That is, they all call foo.__format__(""). If foo.__format__ (well, really type(foo).__format__) doesn't exist, then object.__format__(foo, "") gets called. It's object.__format__ that's checking for the empty format string, and if so it returns str(foo).

What would you suggest changing the ':d' error message to, for objects that don't support a format type of 'd'? This makes sense to me:

>>> format('', 'd')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Unknown format code 'd' for object of type 'str'

The problem, if there is one, is:
>>> format([], 'd')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Unknown format code 'd' for object of type 'str'

The problem is that the str that's producing this error doesn't know that it exists because object.__format__ returned str([]).
History
Date User Action Args
2012-01-21 00:16:25eric.smithsetrecipients: + eric.smith, terry.reedy, r.david.murray, docs@python, py.user
2012-01-21 00:16:25eric.smithsetmessageid: <1327104985.35.0.90065015845.issue13790@psf.upfronthosting.co.za>
2012-01-21 00:16:21eric.smithlinkissue13790 messages
2012-01-21 00:16:21eric.smithcreate