[New-bugs-announce] [issue31335] str.format should support "{:r}" for any type.
Alastair Houghton
report at bugs.python.org
Mon Sep 4 03:01:10 EDT 2017
New submission from Alastair Houghton:
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.
----------
components: Interpreter Core, Library (Lib)
messages: 301211
nosy: al45tair
priority: normal
severity: normal
status: open
title: str.format should support "{:r}" for any type.
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue31335>
_______________________________________
More information about the New-bugs-announce
mailing list