[New-bugs-announce] [issue21071] struct.Struct.format is bytes, but should be str

Zbyszek Jędrzejewski-Szmek report at bugs.python.org
Wed Mar 26 18:48:53 CET 2014


New submission from Zbyszek Jędrzejewski-Szmek:

In Python 2, Struct.format used to be a str. In Python 3 it is bytes, which is unexpected.

Why do I expect .format to be a string:
- This format is pretty much the same as a "{}-format" - plain text
- according to documentation it is composed of things like characters from a closed set '<.=@hi...', a subset of ASCII,
- it is always called "format string" in the documentation

Why is this a problem:
- If I use a str format in constructor, I expect to get a str format,
- Comparisons are broken:

>>> struct.Struct('x').format == 'x'
False
>>> struct.Struct('x').format[0] == 'x'
False

- doctests are broken
>>> struct.Struct('x').format
'x' # in Python 2
b'x' # in Python 3

----------
components: Library (Lib)
messages: 214903
nosy: zbysz
priority: normal
severity: normal
status: open
title: struct.Struct.format is bytes, but should be str
type: behavior
versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5

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


More information about the New-bugs-announce mailing list