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.

classification
Title: No struct.pack exception for some out of range integers
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: bob.ippolito Nosy List: bob.ippolito, georg.brandl, isandler, moese
Priority: normal Keywords:

Created on 2005-06-28 23:30 by moese, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
struct-unsignedlong.diff georg.brandl, 2006-02-20 20:52
Messages (5)
msg25667 - (view) Author: Moese (moese) Date: 2005-06-28 23:30
struct.pack("B", -1) generates an OverflowError
exception since the B format corresponds to the
"unsigned char" type which can have values between 0
and 255.

But struct.pack("I", -1) and struct.pack("L", -1) do
not generate these errors, even if struct.pack("I",
-1L) and struct.pack("L", -1L) do (notice the final L).
msg25668 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-02-20 20:52
Logged In: YES 
user_id=849994

Attaching patch, raises struct.error. Neal, please look over it.

Note that I find struct's error handling confusing: it's not
clear from the docs in which cases OverflowError is raised,
and in which struct.error.
msg25669 - (view) Author: Ilya Sandler (isandler) Date: 2006-04-27 14:46
Logged In: YES 
user_id=971153


Also it appears that there is some kind of interference
between range checking and byte-order chars:

  import struct; struct.pack("H", 70000)  #Exception

  import struct; struct.pack(">H", 70000) # no exception
msg25670 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-05-24 10:25
Logged In: YES 
user_id=849994

Assigning to Bob since he rewrote/extended the struct module
for 2.5.
msg25671 - (view) Author: Bob Ippolito (bob.ippolito) * (Python committer) Date: 2006-05-26 13:16
Logged In: YES 
user_id=139309

The test suite now covers this issue and it's fixed in revision 46320.

Note that this is definitely a backwards incompatible change and we might have 
to change it to a warning or something stupid like that.
History
Date User Action Args
2022-04-11 14:56:12adminsetgithub: 42138
2005-06-28 23:30:21moesecreate