[issue7994] object.__format__ should reject format strings
Eric V. Smith
report at bugs.python.org
Thu Mar 20 01:47:29 CET 2014
Eric V. Smith added the comment:
BreamoreBoy:
This is basically the definition of object.__format__:
def __format__(self, specifier):
if len(specifier) == 0:
return str(self)
raise TypeError('non-empty format string passed to object.__format__')
Which is why it works for an empty specifier.
As a reminder, the point of raising this type error is described in the first message posted in this bug. This caused us an actual problem when we implemented complex.__format__, and I don't see object.__format__ changing.
Implementing NoneType.__format__ and having it understand some string specifiers would be possible, but I'm against it, for reasons I hope I've made clear.
As to why None.__format__ appears to be implemented, it's the same as this:
>>> class Foo: pass
...
>>> Foo().__format__
<built-in method __format__ of Foo object at 0xb74e6a4c>
That's really object.__format__, bound to a Foo instance.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7994>
_______________________________________
More information about the Python-bugs-list
mailing list