Message 219609 - Python tracker (original) (raw)
I reconsidered this in the light of #21559. getargs_b requires an integer of type int in range(256). A non-int properly raises TypeError.
from _testcapi import getargs_b as gb gb(1.0) Traceback (most recent call last): File "<pyshell#7>", line 1, in gb(1.0) TypeError: integer argument expected, got float import fractions gb(fractions.Fraction(1, 1)) Traceback (most recent call last): File "<pyshell#12>", line 1, in gb(fractions.Fraction(1, 1)) TypeError: an integer is required (got type Fraction)
An out-of-range int should, it seems to me, just raise ValueError("int %d not in range(256)" % n). Verification of the range:
gb(255) 255 gb(256) Traceback (most recent call last): File "<pyshell#4>", line 1, in gb(256) OverflowError: unsigned byte integer is greater than maximum gb(0) 0 gb(-1) Traceback (most recent call last): File "<pyshell#6>", line 1, in gb(-1) OverflowError: unsigned byte integer is less than minimum
The last message is wrong or contradictory. An unsigned (non-negative) int cannot be less than 0.