Issue 19985: Not so correct error message when initializing Struct with ill argument (original) (raw)

Issue19985

Created on 2013-12-15 09:28 by vajrasky, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
better_error_message_struct_python_34_and_33.patch vajrasky,2013-12-15 09:28 Python 3.3 and 3.4 review
better_error_message_struct_python_27.patch vajrasky,2013-12-15 09:29 Python 2.7 review
better_error_message_struct_python_34_and_33_v2.patch vajrasky,2013-12-15 14:43 Python 3.3 and 3.4 review
Messages (6)
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) * (Python committer) 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) * (Python committer) 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) * (Python committer) Date: 2017-09-13 20:48
For Python 2.7, this change doesn’t seem important enough for a bug fix.
History
Date User Action Args
2022-04-11 14:57:55 admin set github: 64184
2017-09-14 03:26:10 xiang.zhang set versions: + Python 3.6, Python 3.7, - Python 3.3, Python 3.4
2017-09-14 03:25:33 xiang.zhang set status: open -> closeddependencies: + fix several error messages in struct, - Document whether it's safe to use bytes for struct format stringresolution: fixedstage: resolved
2017-09-13 20:48:14 martin.panter set messages: +
2016-04-15 04:00:33 martin.panter set dependencies: + Document whether it's safe to use bytes for struct format string, - Not so correct error message when initializing Struct with ill argument
2016-04-15 04:00:33 martin.panter unlink issue19985 dependencies
2016-04-14 23:43:40 martin.panter set dependencies: + Not so correct error message when initializing Struct with ill argument
2016-04-14 23:43:40 martin.panter link issue19985 dependencies
2015-02-16 22:06:14 martin.panter set nosy: + martin.pantermessages: +
2013-12-15 14:43:10 vajrasky set files: + better_error_message_struct_python_34_and_33_v2.patchmessages: +
2013-12-15 13:40:49 serhiy.storchaka set nosy: + mark.dickinson, meador.inge
2013-12-15 13:40:25 serhiy.storchaka set nosy: + serhiy.storchakamessages: + versions: - Python 2.7
2013-12-15 09:29:11 vajrasky set files: + better_error_message_struct_python_27.patchmessages: +
2013-12-15 09:28:50 vajrasky create