Eric V. Smith <e...@trueblade.com> added the comment:
This is because Exception does not define __format__, so object.__format__ is being called. object.__format__ does not allow any format specifier to be used. You get the same error for any object without its own __format__, when you supply a format spec. >>> 'okay {0:s}'.format(sys) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported format string passed to module.__format__ The reason this is enforced is because it allows an Execption.__format__ to be added in the future, without worrying what existing format specifiers are being used. We had a problem adding complex.__format__ because people had supplied format specs when formatting complex numbers, assuming they acted like strings. But now we've prevented this problem from happening in the future. If you want to provide str formatting options to something like an exception, you should force-convert it to a str first, using !s: >>> 'okay {0!s:*^10}'.format(Exception('test')) 'okay ***test***' ---------- components: +Interpreter Core -ctypes nosy: +eric.smith resolution: -> not a bug stage: -> resolved status: open -> closed type: -> behavior _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33848> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com