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.

Author steven.daprano
Recipients steven.daprano
Date 2021-08-28.01:02:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1630112525.53.0.10403701832.issue45034@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2021-08-28 01:02:05steven.dapranosetrecipients: + steven.daprano
2021-08-28 01:02:05steven.dapranosetmessageid: <1630112525.53.0.10403701832.issue45034@roundup.psfhosted.org>
2021-08-28 01:02:05steven.dapranolinkissue45034 messages
2021-08-28 01:02:05steven.dapranocreate