[issue28385] Bytes objects should reject all formatting codes with an error message

Serhiy Storchaka report at bugs.python.org
Sat Oct 8 10:06:52 EDT 2016


Serhiy Storchaka added the comment:

Sorry, but it looks to me that issue28385.diff solves wrong issue. The issue is not in bytes, but in default __format__. object.__format__ should raise an error message that contains the name of the actual type. There are other issues with object.__format__, following patch tries to solve them.

1. Error message now contains the name of the actual type.

2. Format spec is checked before converting the value to str. Converting bytes and bytearray to str can raise a BytesWarning, and it is better if the type of this error doesn't depend on the -b option.

3. Since format spec is always empty, avoid calling PyObject_Format(). In theory PyObject_Str() can raise a subclass of str with non-trivial __format__, but I think we can ignore this subtle behavior difference.

----------
nosy: +serhiy.storchaka
Added file: http://bugs.python.org/file45015/object___format__.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28385>
_______________________________________


More information about the Python-bugs-list mailing list