This makes the changes I suggested in bug #457979:
> Lookie:
>
> if (size < 0) {
> PyErr_BadInternalCall();
> return NULL;
> }
>
> if (size < 0 || size > 255) {
> /* Too big or too small */
> PyErr_SetString(PyExc_ValueError, "StaticTuple(...)"
> " takes from 0 to 255 items");
> return NULL;
> }
>
> Not only is this redundant, but PyErr_BadInternalCall() throws a
> TypeError, meaning two different exception classes are used.
>
> ISTM StaticTuple_New should throw a ValueError, since you do
> StaticTuple_New(length), and StaticTuple_new_constructor should throw a
> TypeError, since you do StaticTuple(foo, bar, baz) (currently it lets
> StaticTuple_New handle throw the error).
>
> FYI, the Python version of StaticTuple throws a ValueError when it's
> either <0 or >255. IMO, that should be a TypeError, same as
> StaticTuple_new_constructor.
* bzrlib/_static_tuple_c.c:
(StaticTuple_New): Raise a ValueError when size <0, just like when it's >255.
(StaticTuple_new_constructor): Raise a TypeError when this happens, instead of letting StaticTuple_New raise its ValueError.
* bzrlib/_static_tuple_py.py:
(StaticTuple.__init__): Change the ValueError to a TypeError as well. Move the length check before the type checks, to match StaticTuple_new_constructor, and copy over its error message, since I like it better and it doesn't refer to "key bits".
* bzrlib/tests/test__static_tuple.py:
(TestStaticTuple.test_create_bad_args): Make the relevant type adjustments.
This makes the changes I suggested in bug #457979:
> Lookie: alCall( ); (PyExc_ ValueError, "StaticTuple(...)" alCall( ) throws a New(length) , and StaticTuple_ new_constructor should throw a new_constructor .
>
> if (size < 0) {
> PyErr_BadIntern
> return NULL;
> }
>
> if (size < 0 || size > 255) {
> /* Too big or too small */
> PyErr_SetString
> " takes from 0 to 255 items");
> return NULL;
> }
>
> Not only is this redundant, but PyErr_BadIntern
> TypeError, meaning two different exception classes are used.
>
> ISTM StaticTuple_New should throw a ValueError, since you do
> StaticTuple_
> TypeError, since you do StaticTuple(foo, bar, baz) (currently it lets
> StaticTuple_New handle throw the error).
>
> FYI, the Python version of StaticTuple throws a ValueError when it's
> either <0 or >255. IMO, that should be a TypeError, same as
> StaticTuple_
* bzrlib/ _static_ tuple_c. c: new_constructor ): Raise a TypeError when this happens, instead of letting StaticTuple_New raise its ValueError.
(StaticTuple_New): Raise a ValueError when size <0, just like when it's >255.
(StaticTuple_
* bzrlib/ _static_ tuple_py. py: __init_ _): Change the ValueError to a TypeError as well. Move the length check before the type checks, to match StaticTuple_ new_constructor , and copy over its error message, since I like it better and it doesn't refer to "key bits".
(StaticTuple.
* bzrlib/ tests/test_ _static_ tuple.py: e.test_ create_ bad_args) : Make the relevant type adjustments.
(TestStaticTupl