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 2012年05月24日 06:21 by mesheb82, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| issue14897.patch | makimat, 2012年10月23日 12:50 | review | ||
| issue14897-2.patch | makimat, 2012年10月24日 06:21 | |||
| Messages (16) | |||
|---|---|---|---|
| msg161481 - (view) | Author: mesheb82 (mesheb82) | Date: 2012年05月24日 06:21 | |
I found some unexpected behavior while working with the struct module.
>>> import struct
This works as expected:
>>> struct.pack('1s1s','3','4')
'34'
In this case, with bad input, the error message says I need 2 arguments, when I provide 2 arguments.
>>> struct.pack('1s1s','33')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: pack requires exactly 2 arguments
|
|||
| msg161482 - (view) | Author: mesheb82 (mesheb82) | Date: 2012年05月24日 06:23 | |
Also, I tested this on Windows in Python 3.2.3 and Windows in Python 2.7.2 |
|||
| msg161487 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2012年05月24日 08:22 | |
Hmm. Yes, that's not very clear. The same message is used both for struct.pack and for Struct.pack (which struct.pack is really just a convenient alias for); it makes a bit more sense for the latter:
>>> struct.Struct('1s1s').pack('33')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: pack requires exactly 2 arguments
|
|||
| msg161488 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2012年05月24日 08:41 | |
Funny. struct.pack(fmt, args...) is just an alias to struct.Struct(fmt).pack(args...). The error message should be changed to explicitly state that we are talking about the data for packing, and not about the arguments of function. Or should remove mention of the number of arguments at all (leave only "too much" or "too little"). |
|||
| msg161489 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2012年05月24日 08:47 | |
It might help if the error message also stated how many arguments were actually received, like the TypeError message already does for bad function / method calls. E.g., "struct.error: pack expected 2 items for packing (got 1)" |
|||
| msg161493 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2012年05月24日 09:33 | |
> It might help if the error message also stated how many arguments were actually received, like the TypeError message already does for bad function / method calls. E.g.,
>
> "struct.error: pack expected 2 items for packing (got 1)"
Yes, this would be useful. But seldom implemented.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not enough arguments for format string
>>> '%s %s'%(123,456,789)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
struct.pack also inconsistent in other error messages.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: argument for 's' must be a bytes object
>>> struct.pack('i', '123')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: required argument is not an integer
For "s" is mentioned format, and for "i" no. It would be helpful to
mention also the number of the item.
|
|||
| msg173608 - (view) | Author: Matti Mäki (makimat) * | Date: 2012年10月23日 12:50 | |
Changed the error message as suggested by http://bugs.python.org/issue14897#msg161493 Also made similar change to struct.pack_into |
|||
| msg173652 - (view) | Author: Matti Mäki (makimat) * | Date: 2012年10月24日 06:21 | |
A second try, now taking into account buffer and offset params in pack_into. |
|||
| msg173656 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2012年10月24日 08:34 | |
LGTM. |
|||
| msg174143 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2012年10月29日 19:29 | |
New changeset 626ed0e06fd6 by Petri Lehtinen in branch '2.7': #14897: Enhance error messages of struct.pack and struct.pack_into http://hg.python.org/cpython/rev/626ed0e06fd6 New changeset a555bd4026b0 by Petri Lehtinen in branch '3.2': #14897: Enhance error messages of struct.pack and struct.pack_into http://hg.python.org/cpython/rev/a555bd4026b0 New changeset 70d5906e0461 by Petri Lehtinen in branch '3.3': #14897: Enhance error messages of struct.pack and struct.pack_into http://hg.python.org/cpython/rev/70d5906e0461 New changeset ebc588a3db51 by Petri Lehtinen in branch 'default': #14897: Enhance error messages of struct.pack and struct.pack_into http://hg.python.org/cpython/rev/ebc588a3db51 |
|||
| msg174144 - (view) | Author: Petri Lehtinen (petri.lehtinen) * (Python committer) | Date: 2012年10月29日 19:29 | |
Applied, thanks! |
|||
| msg174185 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2012年10月30日 09:06 | |
Matti Mäki, can you please submit a contributor form? http://python.org/psf/contrib/contrib-form/ http://python.org/psf/contrib/ |
|||
| msg174189 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2012年10月30日 09:36 | |
> "Enhance error messages of struct.pack and struct.pack_into" You probably should have used the word 'fix' rather than 'enhance' here: else it smells like you're putting new features into a maintenance release. :-) |
|||
| msg174191 - (view) | Author: Petri Lehtinen (petri.lehtinen) * (Python committer) | Date: 2012年10月30日 09:44 | |
> You probably should have used the word 'fix' rather than 'enhance' here: else it smells like you're putting new features into a maintenance release. :-) Ah, true. But unfixable now :( |
|||
| msg174194 - (view) | Author: Matti Mäki (makimat) * | Date: 2012年10月30日 10:03 | |
I filled up the contributor form and gave it to Petri Lehtinen 2012年10月22日 |
|||
| msg174195 - (view) | Author: Petri Lehtinen (petri.lehtinen) * (Python committer) | Date: 2012年10月30日 10:05 | |
Matti Mäki wrote: > I filled up the contributor form and gave it to Petri Lehtinen 2012年10月22日 Yeah, and I posted it (along with 14 other contributor forms received at PyCon Finland) to the PSF last week. They just seem to be a bit slow to process them. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:30 | admin | set | github: 59102 |
| 2012年10月30日 10:05:05 | petri.lehtinen | set | messages: + msg174195 |
| 2012年10月30日 10:03:14 | makimat | set | messages: + msg174194 |
| 2012年10月30日 09:44:36 | petri.lehtinen | set | messages: + msg174191 |
| 2012年10月30日 09:36:31 | mark.dickinson | set | messages: + msg174189 |
| 2012年10月30日 09:06:59 | serhiy.storchaka | set | messages: + msg174185 |
| 2012年10月29日 19:29:52 | petri.lehtinen | set | status: open -> closed nosy: + petri.lehtinen messages: + msg174144 resolution: fixed stage: commit review -> resolved |
| 2012年10月29日 19:29:05 | python-dev | set | nosy:
+ python-dev messages: + msg174143 |
| 2012年10月24日 21:26:07 | ezio.melotti | set | nosy:
+ ezio.melotti |
| 2012年10月24日 08:34:18 | serhiy.storchaka | set | stage: commit review messages: + msg173656 components: + Extension Modules versions: + Python 3.4 |
| 2012年10月24日 06:21:14 | makimat | set | files:
+ issue14897-2.patch messages: + msg173652 |
| 2012年10月23日 12:50:59 | makimat | set | files:
+ issue14897.patch nosy: + makimat messages: + msg173608 keywords: + patch |
| 2012年05月25日 16:30:43 | tshepang | set | nosy:
+ tshepang |
| 2012年05月24日 09:33:34 | serhiy.storchaka | set | messages: + msg161493 |
| 2012年05月24日 08:47:30 | mark.dickinson | set | messages: + msg161489 |
| 2012年05月24日 08:41:13 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg161488 |
| 2012年05月24日 08:22:21 | mark.dickinson | set | nosy:
+ mark.dickinson messages: + msg161487 versions: + Python 3.3 |
| 2012年05月24日 06:23:46 | mesheb82 | set | messages: + msg161482 |
| 2012年05月24日 06:21:58 | mesheb82 | create | |