[issue23466] Inconsistency between str and bytes formatting of integers

Serhiy Storchaka report at bugs.python.org
Sun Feb 15 19:21:46 CET 2015


New submission from Serhiy Storchaka:

PEP 461 says that all numeric bytes formatting codes will work as they do for str. In particular b"%x" % val is equivalent to ("%x" % val).encode("ascii"). But this is wrong with current implementation:

>>> '%x' % 3.14
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: %x format: an integer is required, not float
>>> b'%x' % 3.14
b'3'

The same is for %X, %o and %c.

Raising TypeError on non-integer input to %c, %o, %x, and %X was added in issue19995.

----------
components: Interpreter Core
messages: 236056
nosy: ethan.furman, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Inconsistency between str and bytes formatting of integers
type: behavior
versions: Python 3.5

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


More information about the Python-bugs-list mailing list