msg206218 - (view) |
Author: Vajrasky Kok (vajrasky) * |
Date: 2013-12-15 09:28 |
Python 3.4 (3.3 is also afflicted: >>> import struct >>> struct.Struct(3) Traceback (most recent call last): File "", line 1, in TypeError: Struct() argument 1 must be a bytes object, not int >>> struct.Struct('b') <Struct object at 0x7fec04763180> Python 2.7: >>> import struct >>> struct.Struct(3) Traceback (most recent call last): File "", line 1, in TypeError: Struct() argument 1 must be string, not int >>> struct.Struct(u'b') <Struct object at 0x17993e8> Here is the patch to better error message for Python 3.4 and 3.3. |
|
|
msg206219 - (view) |
Author: Vajrasky Kok (vajrasky) * |
Date: 2013-12-15 09:29 |
And here is the patch to better error message in Python 2.7. |
|
|
msg206233 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-12-15 13:40 |
I think that error message in 2.7 is correct. "String" means both str and unicode. As for 3.x, agree, it should be corrected. But I prefer "str or bytes" or "string or bytes object". |
|
|
msg206235 - (view) |
Author: Vajrasky Kok (vajrasky) * |
Date: 2013-12-15 14:43 |
Here is the patch to address Serhiy's request. Hmmm, if string means both string and unicode in Python 2.7, should we fix these behaviours? >>> import _csv >>> _csv.register_dialect(2) Traceback (most recent call last): File "", line 1, in TypeError: dialect name must be a string or unicode >>> ' cute cat '.strip(3) Traceback (most recent call last): File "", line 1, in TypeError: strip arg must be None, str or unicode >>> import sqlite3 >>> conn = sqlite3.connect(':memory:') >>> c = conn.cursor() >>> c.execute(3) Traceback (most recent call last): File "", line 1, in ValueError: operation parameter must be str or unicode |
|
|
msg236115 - (view) |
Author: Martin Panter (martin.panter) *  |
Date: 2015-02-16 22:06 |
Closely related: * Issue 16349: document byte string format argument support * Issue 21071: should the Struct.format property be bytes or text? |
|
|
msg302113 - (view) |
Author: Martin Panter (martin.panter) *  |
Date: 2017-09-13 20:48 |
For Python 2.7, this change doesn’t seem important enough for a bug fix. |
|
|