Message400452
Packing errors using struct in 3.9 seem to be unnecessarily obfuscated to me.
>>> import struct
>>> struct.pack('H', 70000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: ushort format requires 0 <= number <= (0x7fff * 2 + 1)
Why "0x7fff * 2 + 1"? Why not the more straightforward "0xffff" or 65536? (I have a slight preference for hex.)
Compare that to:
>>> struct.pack('I', 4300000000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: 'I' format requires 0 <= number <= 4294967295
which at least gives the actual value, but it would perhaps be a bit more useful in hex 0xffffffff.
For the long-long format, the error message just gives up:
>>> struct.pack('Q', 2**65)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: argument out of range
Could be improved by:
'Q' format requires 0 <= number <= 0xffff_ffff_ffff_ffff |
|
Date |
User |
Action |
Args |
2021-08-28 01:02:05 | steven.daprano | set | recipients:
+ steven.daprano |
2021-08-28 01:02:05 | steven.daprano | set | messageid: <1630112525.53.0.10403701832.issue45034@roundup.psfhosted.org> |
2021-08-28 01:02:05 | steven.daprano | link | issue45034 messages |
2021-08-28 01:02:05 | steven.daprano | create | |
|