[issue45034] Improve struct.pack out of range error messages
Terry J. Reedy
report at bugs.python.org
Fri Sep 3 20:27:10 EDT 2021
Terry J. Reedy <tjreedy at udel.edu> added the comment:
I agree, including use of hex, if possible, for unsigned (non-negative) values.
Grepping 'format requires' returns
F:\dev\3x\Modules\_struct.c: 365: "'%c' format requires 0 <= number <= %zu",
F:\dev\3x\Modules\_struct.c: 371: "'%c' format requires %zd <= number <= %zd",
F:\dev\3x\Modules\_struct.c: 550: "byte format requires -128 <= number <= 127");
F:\dev\3x\Modules\_struct.c: 565: "ubyte format requires 0 <= number <= 255");
F:\dev\3x\Modules\_struct.c: 577: "char format requires a bytes object of length 1");
F:\dev\3x\Modules\_struct.c: 593: "short format requires " Py_STRINGIFY(SHRT_MIN)
F:\dev\3x\Modules\_struct.c: 611: "ushort format requires 0 <= number <= "
Py_STRINGIFY(USHRT_MAX));
I believe l365 is the source for the 2nd example. AFAIK, 'zu' is not valid for either C printf or Python % formating.
Lines 611 and 612 are the source for the 1st example. From comments before line 365, there can be issues with lefts shifts, but '0xffff', '0xffff_ffff', and '0xffff_ffff_ffff_ffff' could be hard-coded strings that would cover all 'normal' systems.
Grepping "argument out of range" returns
F:\dev\3x\Modules\_struct.c: 168: "argument out of range");
F:\dev\3x\Modules\_struct.c: 192: "argument out of range");
F:\dev\3x\Modules\_struct.c: 215: "argument out of range");
F:\dev\3x\Modules\_struct.c: 238: "argument out of range");
F:\dev\3x\Modules\_struct.c: 261: "argument out of range");
F:\dev\3x\Modules\_struct.c: 284: "argument out of range");
It is nnclear to me without more reading why some codes lead to this less helpful message.
----------
nosy: +terry.reedy
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45034>
_______________________________________
More information about the Python-bugs-list
mailing list