◐ Shell
clean mode source ↗

Message 189062 - Python tracker

But int has its own __format__ method, so this does not apply. Per the title of this issue, this only refers to object.__format__.

For example:

This works now, and will continue working:
>>> format(2, '1')
'2'

This is currently an error, and will remain an error:
>>> class C: pass
...
>>> format(C(), '1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: non-empty format string passed to object.__format__

It's this case that is currently an error, but it need not be:
>>> format(object(), '1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: non-empty format string passed to object.__format__

The more I think about it, the more I think it would be too confusing to make object.__format__ behave differently if self is of type object, versus another type. So I'll probably just close this as fixed unless someone feels strongly about it.