This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
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 "<stdin>", line 1, in <module>
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 "<stdin>", line 1, in <module>
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 "<stdin>", line 1, in <module>
TypeError: dialect name must be a string or unicode
>>> ' cute cat '.strip(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
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 "<stdin>", line 1, in <module>
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 -> closed dependencies: + fix several error messages in struct, - Document whether it's safe to use bytes for struct format string resolution: fixed stage: resolved |
| 2017年09月13日 20:48:14 | martin.panter | set | messages: + msg302113 |
| 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.panter messages: + msg236115 |
| 2013年12月15日 14:43:10 | vajrasky | set | files:
+ better_error_message_struct_python_34_and_33_v2.patch messages: + msg206235 |
| 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.storchaka messages: + msg206233 versions: - Python 2.7 |
| 2013年12月15日 09:29:11 | vajrasky | set | files:
+ better_error_message_struct_python_27.patch messages: + msg206219 |
| 2013年12月15日 09:28:50 | vajrasky | create | |