Currently if you do
"{:r}".format(None)
you get the error message
TypeError: non-empty format string passed to object.__format__
or on newer versions
TypeError: non-empty format string passed to NoneType.__format__
(which is at least *some* improvement).
Similar behaviour occurs for other types that don't implement their own __format__ method.
This seems to me to be an error on two counts:
1. object.__format__ *should* support ":r", and probably ":s" too.
2. It's unclear what the error message actually means (I had to Google it to find out what was going wrong), *especially* in a situation where it isn't obvious that the argument evaluates to None.
Since the error itself would still happen if an unsupported specifier was used, we should improve the message. A better choice might be
TypeError: format "{:x}" not supported for type NoneType. |