@@ -783,7 +783,9 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
783
783
if (arg == NULL ) {
784
784
if (encoding != NULL || errors != NULL ) {
785
785
PyErr_SetString (PyExc_TypeError ,
786
- "encoding or errors without sequence argument" );
786
+ encoding != NULL ?
787
+ "encoding without a string argument" :
788
+ "errors without a string argument" );
787
789
return -1 ;
788
790
}
789
791
return 0 ;
@@ -812,7 +814,9 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
812
814
/* If it's not unicode, there can't be encoding or errors */
813
815
if (encoding != NULL || errors != NULL ) {
814
816
PyErr_SetString (PyExc_TypeError ,
815
- "encoding or errors without a string argument" );
817
+ encoding != NULL ?
818
+ "encoding without a string argument" :
819
+ "errors without a string argument" );
816
820
return -1 ;
817
821
}
818
822
@@ -860,8 +864,14 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
860
864
861
865
/* Get the iterator */
862
866
it = PyObject_GetIter (arg );
863
- if (it == NULL )
867
+ if (it == NULL ) {
868
+ if (PyErr_ExceptionMatches (PyExc_TypeError )) {
869
+ PyErr_Format (PyExc_TypeError ,
870
+ "cannot convert '%.200s' object to bytearray" ,
871
+ arg -> ob_type -> tp_name );
872
+ }
864
873
return -1 ;
874
+ }
865
875
iternext = * Py_TYPE (it )-> tp_iternext ;
866
876
867
877
/* Run the iterator to exhaustion */
@@ -1626,8 +1636,14 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints)
1626
1636
}
1627
1637
1628
1638
it = PyObject_GetIter (iterable_of_ints );
1629
- if (it == NULL )
1639
+ if (it == NULL ) {
1640
+ if (PyErr_ExceptionMatches (PyExc_TypeError )) {
1641
+ PyErr_Format (PyExc_TypeError ,
1642
+ "can't extend bytearray with %.100s" ,
1643
+ iterable_of_ints -> ob_type -> tp_name );
1644
+ }
1630
1645
return NULL ;
1646
+ }
1631
1647
1632
1648
/* Try to determine the length of the argument. 32 is arbitrary. */
1633
1649
buf_size = PyObject_LengthHint (iterable_of_ints , 32 );
0 commit comments