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 <rep...@bugs.python.org>
<http://bugs.python.org/issue31335>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to