New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange DeprecationWarning behaviour in module struct #49448
Comments
struct.pack seems to raise a DeprecationWarning for some structure 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 $ python2.6 struct_warning.py
struct_warning.py:6: DeprecationWarning: integer argument expected, got
float
foo() |
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 "<string>", line 1, in <module>
struct.error: ubyte format requires 0 <= number <= 255 .../trunk> ./python -c 'import struct; struct.pack(">B", 257)' |
It appears that the different behavior results from trying to preserve |
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". |
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' |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: