Message151711
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([]). |
|
Date |
User |
Action |
Args |
2012-01-21 00:16:25 | eric.smith | set | recipients:
+ eric.smith, terry.reedy, r.david.murray, docs@python, py.user |
2012-01-21 00:16:25 | eric.smith | set | messageid: <1327104985.35.0.90065015845.issue13790@psf.upfronthosting.co.za> |
2012-01-21 00:16:21 | eric.smith | link | issue13790 messages |
2012-01-21 00:16:21 | eric.smith | create | |
|