Issue 5198: Strange DeprecationWarning behaviour in module struct (original) (raw)

Created on 2009-02-10 07:14 by hagen, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
struct_warning.py hagen,2009-02-10 07:14
Messages (5)
msg81532 - (view) Author: Hagen Fürstenau (hagen) Date: 2009-02-10 07:14
struct.pack seems to raise a DeprecationWarning for some structure formats, but not for others: Python 2.6.1 (r261:67515, Dec 5 2008, 07:40:41) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import struct >>> struct.pack(">H", 1.0) sys:1: DeprecationWarning: integer argument expected, got float '\x00\x01' >>> struct.pack("H", 1.0) '\x01\x00' In addition the DeprecationWarning message gives a strange location for the problem. With the attached struct_warning.py it locates the problem at the function call foo() instead of the problematic call of struct.pack: $ python2.6 struct_warning.py struct_warning.py:6: DeprecationWarning: integer argument expected, got float foo()
msg83159 - (view) Author: Ilya Sandler (isandler) Date: 2009-03-04 23:01
Here is another case, which I think is even worse. Range checks are done inconsistently as well: .../trunk> ./python -c 'import struct; struct.pack("B", 257) 'Traceback (most recent call last): File "", line 1, in struct.error: ubyte format requires 0 <= number <= 255 .../trunk> ./python -c 'import struct; struct.pack(">B", 257)' sys:1: DeprecationWarning: 'B' format requires 0 <= number <= 255
msg83206 - (view) Author: Ilya Sandler (isandler) Date: 2009-03-05 17:29
It appears that the different behavior results from trying to preserve backward compatibility with earlier version of Python see: http://bugs.python.org/issue1229380
msg102367 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-04-05 10:35
Both examples now give consistent behavior independent of byteorder in trunk: packing floats with "H" works, packing bytes out of range with "B" raises. Closing as "out of date".
msg102469 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-04-06 15:23
The wrong location for the DeprecationWarnings was also fixed in trunk in r78690. I've backported the fix to release26-maint in r79834. I don't dare mess further with the warnings in a bugfix release; as Georg points out, the issues are fixed in trunk. BTW, one of the 2.6 issues (again fixed in trunk) that wasn't mentioned above is that some packs produce *two* overflow-related warnings: >>> import struct >>> struct.pack('<L', -1) __main__:1: DeprecationWarning: struct integer overflow masking is deprecated __main__:1: DeprecationWarning: 'L' format requires 0 <= number <= 4294967295 '\xff\xff\xff\xff'
History
Date User Action Args
2022-04-11 14:56:45 admin set github: 49448
2010-04-06 15:23:14 mark.dickinson set nosy: + mark.dickinsonmessages: +
2010-04-05 10:35:58 georg.brandl set status: open -> closednosy: + georg.brandlmessages: + resolution: out of date
2009-03-05 17:29:11 isandler set messages: +
2009-03-04 23:01:55 isandler set nosy: + isandlermessages: +
2009-02-10 07:14:28 hagen create